Customize back navigation

天大地大妈咪最大 提交于 2019-12-12 04:20:41

问题


First of all I read this article but is kind of complicated for me . All I need is to go to an activity I want (navigate if exist in back stack or start it with Intent if it's not ) in onBackPressed() override . should I manage back stack or something else ? if yes how ? and if no what is a simple way for that ?

P.S : I dont use ActionBar


回答1:


you should override the second activity's onBackPressed() method and add android:launchMode="singleInstance" to your first activity in AndroidManifest.xml this will launch the first activity from backstack or create new if it doesn't exist in backstack.




回答2:


Use startActivityForResult() wherever needed. Do not create new instances of the same activity. That is, if u want to go back to the previous activity, just call finish() from this activity.

Understand different launchmodes

As mentioned in the link above, singleInstance launchMode might be tricky and might cause issues.




回答3:


SOLVED: as mentioned in this answer and according to comments , if we want to just bring an (existing )Activity to front , setting Intent flag to :

    Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

wont create new instance of Activity we want and just bring it front . this would be useful if we have multiple activities on top of the one .



来源:https://stackoverflow.com/questions/44698140/customize-back-navigation

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