Finish parent and current activity in Android

前端 未结 16 3071
误落风尘
误落风尘 2020-11-27 03:40

I have 3 activities. Activity A which leads to activity B, which in turn can go back to activity A or start activity C. However, if I press back in activity C the app should

16条回答
  •  無奈伤痛
    2020-11-27 04:05

    From Activity A, start activity B for a result using startActivityForResult(intent,19)

    In Activity B, when the user triggers Activity C, start activity C.

    startActivity() returns immediately, so

    set a result that will inform A to finish as well,

    Call finish() in B. and Call setResult() method before finish() method in your Child Activity In Parent Activity overide onActivtyResult(....) method. When A receives that result from B, A calls finish() on itself as well.

    enter code here
         @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        //Added by Ashish to close parent activity
          if(arg1==19){
          finish();
            }
        super.onActivityResult(arg0, arg1, arg2);
    }
    

提交回复
热议问题