From dc316c5669ce9f43a0955d395dfb97be3f836671 Mon Sep 17 00:00:00 2001 From: tonymanou Date: Thu, 12 Jan 2017 00:13:23 +0100 Subject: [PATCH] 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. --- .../main/java/com/topjohnwu/magisk/InstallFragment.java | 8 ++++---- app/src/main/java/com/topjohnwu/magisk/LogFragment.java | 7 ++++++- .../java/com/topjohnwu/magisk/MagiskHideFragment.java | 8 ++++---- .../main/java/com/topjohnwu/magisk/ModulesFragment.java | 8 ++++---- app/src/main/java/com/topjohnwu/magisk/ReposFragment.java | 8 ++++---- .../main/java/com/topjohnwu/magisk/StatusFragment.java | 8 ++++---- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java index 4a598df69..572678ae3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java @@ -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(); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/LogFragment.java b/app/src/main/java/com/topjohnwu/magisk/LogFragment.java index 687aa4e8d..15fd976d4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/LogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/LogFragment.java @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java index 302e649c0..0f6fe8de9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java index 46eee6cb8..ae3c3a15f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java @@ -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() { diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index c59fca176..bfabcd2a4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -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() { diff --git a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java index 12245066a..6b1f8b018 100644 --- a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java @@ -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() {