跳过多个活动

时间:2018-02-19 06:52:00

标签: android

活动流程

第一活动 - > 活动A->活性B->活性C->活性D->活性E

第二活动 - > 活动A->活性B->活性C-> - 活性E. 不需要活动D

1 个答案:

答案 0 :(得分:0)

要跳过一个Activity只需string,然后stringintent发送到NextActivity

尝试使用以下代码:

活动B:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_b);

    //inside click listner
    Intent i = new Intent(ActivityB.this,ActivityC.class);
                i.putExtra("source", "SKIP");
                startActivity(i);

}

<强> ActivityC:

 String source = "";

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_c);

         //if source will skip ActivityD
         if(getIntent().getExtras()!=null)
         {
           source = getIntent().getExtras().getString("source");
         }

         //inside click listner
         if(source.equals("SKIP"))
         {
           Intent i = new Intent(ActivityC.this,ActivityE.class); // Here skip ActivityD
           startActivity(i);

         }else{

           Intent i = new Intent(ActivityC.this,ActivityD.class);
           startActivity(i);
         }

    }