androidandroid-fragmentsandroid-activityup-navigation

what method is called when Actionbar back/home button is pressed?


I have two activities first activity opens on app start and it holds fragment second activity is opened from that fragment, when I press home button second activity closes and in fragment methods onDetach -> onAttach -> onResume is called, but if I close second activity with finish() or onBackPressed() fragment is never detached just onResume() is called.So my question is what method is called when home button is pressed and is there possibility to use same method to close activity for example on button press? Basically what I need is that fragment would call onDetach -> onAttach when I closing second activity.


Solution

  • you can remove the fragment in e.g. onDestroy() of the activity, so the fragment will go through it's lifecycle methods