Set fragment title and [un]register callbacks in onStart/onStop

onStart() is called when the fragment is made visible, whereas onPause()
is called when the fragment looses focus e.g. if a dialog is shown.
Thus:
- there is no need to set the activity's title everytime the fragment
regains focus,
- it is better to listen to event tasks and refresh the state of the UI
while the fragment is actually visible, listening to events until the
fragment is destroyed is useless: if an event is received between
onStop() and onDestroy(), there will be some processing but nothing will
be shown because the fragment is no longer visible.
This commit is contained in:
tonymanou
2017-01-12 00:13:23 +01:00
committed by topjohnwu
parent e9f04256c9
commit dc316c5669
6 changed files with 26 additions and 21 deletions

View File

@@ -93,16 +93,16 @@ public class ModulesFragment extends Fragment implements CallbackHandler.EventLi
}
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
CallbackHandler.register(moduleLoadDone, this);
getActivity().setTitle(R.string.modules);
}
@Override
public void onDestroy() {
super.onDestroy();
public void onStop() {
CallbackHandler.unRegister(moduleLoadDone, this);
super.onStop();
}
private void updateUI() {