android insert into activity stack

家住魔仙堡 提交于 2020-01-02 03:30:11

问题


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


回答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();
}


来源:https://stackoverflow.com/questions/10163769/android-insert-into-activity-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!