问题
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