0

While adding a new fragment in a back-stack from preference fragment, the Preference fragment life-cycle events onPause() & onResume() is not getting called, when a new fragment is added on top of it.

Due to this, I am not able to update the summary of the item view in the settings fragment.

This code adds the detail fragment on top of settings preference fragment

getSupportFragmentManager().beginTransaction()
                       .add(R.id.settings_container, new SettingsDetailFragment(), "SettingsDetailFragment")
                       .commit();

This code handles the backPress

if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
    this.finish();
} else {
    setToolbarTitle("Settings");
    getSupportFragmentManager().popBackStack();
}
Ajay Mehta
  • 843
  • 5
  • 14
Ravi Parmar
  • 43
  • 1
  • 12
  • Have you tried to add both onPause() and onResume() methods in your Parent Activity? – Ajay Mehta Apr 26 '19 at 07:52
  • @AjayMehta-Rlogical Yes . its not getting called . When minimize the app the lifecycle events are called .Starting with Settings Activity ,Preference and then detail Settings . But when a new fragment is added on top of preference fragment this is not called – Ravi Parmar Apr 26 '19 at 07:55
  • Fragments `onPause` and `onResume()` will not get called on popBackStack . These methods are bind to Activities life cycle and only will get called if Activity is Pause or resumed . You can use `LocalBroadcast` or EventBus or some other approach to notify previous fragment .. – ADM Apr 26 '19 at 08:31

0 Answers0