7

Here is the question: Let's say the activity stack consist of A->B->C.

If user followed the order eg: Start A -> B -> C, pressing back button will cause C->B->A. However, if user entered directly into activity C (eg: via notification), pressing back button will cause the app to close, instead of going into B->A.

How do I insert the into the activity stack to become A->B->C, so that when user pressed back at C, it will always back to B.

Thanks

Bananakilo
  • 1,323
  • 3
  • 14
  • 20

1 Answers1

1

just overide the onBackPressed() method and startactivity B in activityc and startactivity a in activity b.

in activty c have these code::

public void onBackPressed(){
startActivity(new Intent(this,ActivityB.class));
finish();
}

and in activity b have these code::

public void onBackPressed(){
startActivity(new Intent(this,ActivityA.class));
finish();
}

and in activity a have these code::

public void onBackPressed(){
finish();
}
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • does this breaks the android activity stack order? It should finish current activity and back to previous, not starting another new activity. – Bananakilo Apr 16 '12 at 11:24
  • This is one of the good solutions.. Its better to use fragments instead of activities for better performance.. – Sripathi Nov 19 '13 at 16:16