0

For example:A start B, B start C, A and C belongs to 'Hello'-stack, and B belongs to 'World'-stack, when user press back button in Activity C, it will return to A. Note1:B means a lot of activities , not just one activity, like A start B1,B1 start B2, B2 start B3....,Bn start C. Note2:I need Bs remain in stack until C has been launched , when user press back in B3, it should return to b2. enter image description here

I actually have implemented this need by using startActivityForResult,and I just want to know is there any way using stack to implements this.

empty-yo
  • 143
  • 1
  • 2
  • 6
  • http://stackoverflow.com/questions/19798737/android-intent-flag-to-destroy-activity-and-start-new-one – Mehul Jul 23 '16 at 07:37

3 Answers3

0

Simply call finish() when you start Activity C from B. Then override onBackPressed() in activity C. And add code to start Activity A.

  • sorry, i did not describe my question clearly..there is more than one activity in 'World'-stack in top of B. – empty-yo Jul 23 '16 at 07:13
  • Clearly tell flow of activities – Balaje Venkat Jul 23 '16 at 08:10
  • Yeah.. Whenever you call a new activity, just destroy the present activity by calling finish() after startActivity(). On Activity C, Override onBackPressed() method. In the method, start activity A.. – Balaje Venkat Jul 23 '16 at 08:53
  • Simply call Intent in=new Intent(ActivityC.this,ActivityA.class); startActivity(in); in onBackPressed() method of ActivityC. Thats it. – Balaje Venkat Jul 23 '16 at 10:10
  • Hey @empty-yo.. your question is clossed ah? I mean your problem is solved or not? If yes, mark my answer as accepted, else reply with your queries. Otherwise this question will be in pending status. – Balaje Venkat Aug 05 '16 at 06:02
0

When going from activity A to activity B, go as below:

 Intent i=new Intent(ActivityA.this,ActivityB.class);
 startActivity(i);

And as you want to open C from B but don't want B to be in stack, so do as below:

 Intent i=new Intent(ActivityB.this,ActivityC.class);
 startActivity(i);
 ActivityB.this.finish();

So automatically when backpressed on C, you will get A and not B.

Dhruvi
  • 1,971
  • 2
  • 10
  • 18
0

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); or intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); works for me.

empty-yo
  • 143
  • 1
  • 2
  • 6