In my android application when I want to implement an up navigation I use Navutils.navigateUpTo(...). But the nice thing is that when you want to navigate only one level up, you can use activity.finish() too. My question is that: Is using of activity.finish() for navigating up safe or not? My concern is that in some cases the parent may not be at the stack and instead of navigating, it finishes the app.
Asked
Active
Viewed 217 times
-3
-
Please instead of voting down, give some reasons or a solution. – Reza Abbasi Nov 08 '15 at 18:08
1 Answers
1
It depends on your activity. If your activity is not the last activity in the stack there is not any problem(like setting_activity) that you go to that from another activity. I think you can check to see if there is any other activity in the stack then use finish()
. else
do another job.

karimkhan
- 321
- 3
- 18
-
Thanks my friend. Is it possible the Android OS clears some of stack because of memory lack during running of an application? – Reza Abbasi Nov 08 '15 at 18:13
-
1@RezaAbbasi: yes this can be done by android OS but you can manage your activities to use finish() when you really need it. and must say that android in its new versions try toimprove use or resources to not happen memory lack. – karimkhan Nov 08 '15 at 18:20
-
Thanks. One more question my friend : How can we check that the parent of an activity exists in the stack? – Reza Abbasi Nov 08 '15 at 18:43
-
use [this](http://stackoverflow.com/questions/5975811/how-to-check-if-an-activity-is-the-last-one-in-the-activity-stack-for-an-applica) – karimkhan Nov 08 '15 at 18:54