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

@ -98,15 +98,15 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi
}
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
getActivity().setTitle(R.string.install);
CallbackHandler.register(blockDetectionDone, this);
}
@Override
public void onDestroy() {
super.onDestroy();
public void onStop() {
CallbackHandler.unRegister(blockDetectionDone, this);
super.onStop();
}
}

View File

@ -70,11 +70,16 @@ public class LogFragment extends Fragment {
return view;
}
@Override
public void onStart() {
super.onStart();
getActivity().setTitle(R.string.log);
}
@Override
public void onResume() {
super.onResume();
new LogManager().read();
getActivity().setTitle(R.string.log);
}
@Override

View File

@ -93,8 +93,8 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
}
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
getActivity().setTitle(R.string.magiskhide);
CallbackHandler.register(packageLoadDone, this);
if (packageLoadDone.isTriggered) {
@ -103,9 +103,9 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
}
@Override
public void onPause() {
super.onPause();
public void onStop() {
CallbackHandler.unRegister(packageLoadDone, this);
super.onStop();
}
@Override

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() {

View File

@ -109,16 +109,16 @@ public class ReposFragment extends Fragment implements CallbackHandler.EventList
}
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
CallbackHandler.register(repoLoadDone, this);
getActivity().setTitle(R.string.downloads);
}
@Override
public void onDestroy() {
super.onDestroy();
public void onStop() {
CallbackHandler.unRegister(repoLoadDone, this);
super.onStop();
}
private void reloadRepos() {

View File

@ -141,8 +141,8 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
}
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
CallbackHandler.register(updateCheckDone, this);
CallbackHandler.register(safetyNetDone, this);
if (updateCheckDone.isTriggered) {
@ -155,10 +155,10 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
}
@Override
public void onPause() {
super.onPause();
public void onStop() {
CallbackHandler.unRegister(updateCheckDone, this);
CallbackHandler.unRegister(safetyNetDone, this);
super.onStop();
}
private static void checkMagiskInfo() {