Customizing Back Stack in Android Activities -
consider there 1 activity, named activity s.
there many activities, 10 activities, named a, b, c, ..., j.
how can achieve this:
a--j activities, when button pressed, go activity s.
regardless of ordering or how activities created.
for example:
starting s, go b, d, g.
in activity g, press button, , go s.
== edit ==
should use activity.finish() method when leaving a--j activities ?
you accomplish in different ways depending on exact result desire. add following line <activity> tags in manifest.xml activities
android:nohistory="true" or use intent flag when overrdiing onbackpressed() in each
@override public void onbackpressed() { intent = new intent(currentactivity.this, s.class); i.setflags(intent.flag_activity_clear_top);` startactivity(i); super.onbackpressed(); } this clear other activities stack , return s.
if want keep activities on stack while returning s can change flag used
@override public void onbackpressed() { intent = new intent(currentactivity.this, s.class); i.setflags(intent.flag_activity_reorder_to_front);` startactivity(i); super.onbackpressed(); } the last way bring s front , keep other activities on stack don't think want option. want 1 of first 2 ways.
Comments
Post a Comment