How to close all child activities from parent in android

前端 未结 5 682
感情败类
感情败类 2020-12-12 08:30

I\'m new to android. Actually one handler is running in Home Activity A for every 30 sec to check the net connection.

If I\'m went to activity C by A->B->C, If ther

相关标签:
5条回答
  • 2020-12-12 08:47

    For example, if you want to start intentB, you can do following in old activity:

    Intent intentB = new Intent();
    intentB.setClass(XYZ.this, abc.class);
    intentB.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intentB);

    0 讨论(0)
  • 2020-12-12 08:49

    You can start Activity A and close all other activities. You have to create new intent and add flag FLAG_ACTIVITY_CLEAR_TOP

    
    Intent activityA = new Intent(context, ActivityA.class);
    activityA.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.StartActivity(activityA);
    

    this will close all activities that are in the stack and are at the top of activity A

    0 讨论(0)
  • 2020-12-12 08:49

    You can use, According to me two ways,

    If you start an activity using startActivityForResult, then you can call finish() in this new Activity when you're done with it and it will return control to the activity that started it.

    OR otherwise, May be I am wrong,

    Call finish inside onStop 'override method'.

    0 讨论(0)
  • 2020-12-12 08:56

    When calling Acitivity C, call finish in activity B , when calling Activity A from C , call finish() in activity C !

    0 讨论(0)
  • 2020-12-12 09:05

    make a uniform resultCode for closing child activities. Eg. you make 911 (should be int) as your resultCode. If you want your Activity to finish and go back directly to parent Activity, you set the resultCode to 911:

    setResult(911); finish();

    In every child activity, you override the onActivityResult and check if the resultCode is 911. If yes, then call the setResult(911); finish(); until you get back to your parent activity. Hope this helps!

    0 讨论(0)
提交回复
热议问题