Issue
I have two activities. When I go to the second activity I have two options to return to previous one:
- Press "back" button on toolbar
- Press physical "back" button at the bottom of screen (to left of home button)
However, I have observed that toolbar back button is calling first onDestroy() on the first activity then recreates it. The physical back button is calling onRestart() in the fisrt activity instead and doesn't destoy it.
Question: Why they behave differently?
Solution
The toolbar back button is actually an "Up" button and it is supposed to take you to the higher level on your app's navigation hierarchy.
Whereas, the physical button takes you to the last place you were looking at. It means, you can end up in a completely different app while pressing the physical back button.
Both the functionalities are important, therefore you need two buttons behaving differently.
Refer to this official doc for understanding it better.
Answered By - Akeshwar Jha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.