Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android insert into activity stack

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

like image 205
Yong Fei Avatar asked Apr 15 '12 16:04

Yong Fei


1 Answers

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();
}
like image 141
Shankar Agarwal Avatar answered Oct 14 '22 22:10

Shankar Agarwal