Currently I'm starting a new Activity
and calling finish
on a current one.
Is there any flag that can be passed to Intent
that enables finishing current Activity
without a need to call finish
manually from code?
Currently I'm starting a new Activity
and calling finish
on a current one.
Is there any flag that can be passed to Intent
that enables finishing current Activity
without a need to call finish
manually from code?
You can use finish()
method or you can use:
android:noHistory="true"
And then there is no need to call finish()
anymore.
<activity android:name=".ClassName" android:noHistory="true" ... />
Use finish
like this:
Intent i = new Intent(Main_Menu.this, NextActivity.class);
finish(); //Kill the activity from which you will go to next activity
startActivity(i);
FLAG_ACTIVITY_NO_HISTORY
you can use in case for the activity you want to finish. For exampe you are going from A-->B--C. You want to finish activity B when you go from B-->C so when you go from A-->B you can use this flag. When you go to some other activity this activity will be automatically finished.
To learn more on using Intent.FLAG_ACTIVITY_NO_HISTORY
read: http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY
finish()
suppose to kill the current activity ? how do you expect it to reach the next line startActivity(i)
? Looks dangerous and unexpected to me –
Carycaryatid FLAG_ACTIVITY_NO_HISTORY when starting the activity you wish to finish after the user goes to another one.
http://developer.android.com/reference/android/content/Intent.html#FLAG%5FACTIVITY%5FNO%5FHISTORY
© 2022 - 2024 — McMap. All rights reserved.