androidup-navigation

Is activity.finish() safe enough for up navigation action


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.


Solution

  • 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.