diff --git a/app/src/main/java/eu/faircode/email/ActivityBilling.java b/app/src/main/java/eu/faircode/email/ActivityBilling.java index 3ad352a97f..d4c83496ff 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBilling.java +++ b/app/src/main/java/eu/faircode/email/ActivityBilling.java @@ -153,7 +153,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (ACTION_PURCHASE.equals(intent.getAction())) onPurchase(intent); else if (ACTION_PURCHASE_CHECK.equals(intent.getAction())) diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 5c4e45917b..f073642e3f 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -207,7 +207,7 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) onBackPressed(); return true; default: @@ -234,7 +234,7 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (ACTION_SHOW_PRO.equals(intent.getAction())) onShowPro(intent); } @@ -242,7 +242,7 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. }; private void onShowPro(Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("pro", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 6f80600868..c90bf97c6c 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -349,7 +349,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac switch (item.getItemId()) { case android.R.id.home: - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack(); return true; } @@ -407,7 +407,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac } private void onMenuOrder(int title, Class clazz) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("order", FragmentManager.POP_BACK_STACK_INCLUSIVE); Bundle args = new Bundle(); @@ -450,7 +450,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac } private void onMenuContacts() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("contacts", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -459,7 +459,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac } private void onMenuLegend() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("legend", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -480,7 +480,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac } private void onMenuAbout() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("about", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -1091,7 +1091,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { String action = intent.getAction(); if (ACTION_QUICK_SETUP.equals(action)) onViewQuickSetup(intent); diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index d4cbcb0906..b5c5290f75 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -479,11 +479,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB setIntent(intent); if ("unified".equals(action)) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("unified", 0); } else if ("why".equals(action)) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("unified", 0); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityView.this); @@ -627,7 +627,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB switch (item.getItemId()) { case android.R.id.home: - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack(); return true; default: @@ -813,7 +813,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onMenuFolders(long account) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("unified", 0); Bundle args = new Bundle(); @@ -840,7 +840,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override protected void onExecuted(Bundle args, Long folder) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("unified", 0); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(ActivityView.this); @@ -858,7 +858,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onMenuOperations() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("operations", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -867,7 +867,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onMenuAnswers() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("answers", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -880,7 +880,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onMenuLegend() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("legend", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -905,7 +905,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onMenuAbout() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("about", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -959,7 +959,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onShowLog() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("logs", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); @@ -970,7 +970,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { String action = intent.getAction(); if (ACTION_VIEW_FOLDERS.equals(action)) @@ -1003,7 +1003,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onViewMessages(Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("messages", FragmentManager.POP_BACK_STACK_INCLUSIVE); Bundle args = new Bundle(); @@ -1030,7 +1030,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private void onViewThread(Intent intent) { boolean found = intent.getBooleanExtra("found", false); - if (!found && getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (!found && getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE); Bundle args = new Bundle(); @@ -1095,7 +1095,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onShowPro(Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("pro", FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 394dd0b591..f52cac1260 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -1067,7 +1067,7 @@ public class FragmentAccount extends FragmentBase { fragment.setArguments(aargs); fragment.setTargetFragment(FragmentAccount.this, REQUEST_SAVE); fragment.show(getFragmentManager(), "account:save"); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } @@ -1316,7 +1316,7 @@ public class FragmentAccount extends FragmentBase { } }); onSave(false); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); break; case REQUEST_DELETE: @@ -1363,7 +1363,7 @@ public class FragmentAccount extends FragmentBase { @Override protected void onExecuted(Bundle args, Void data) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 372dbaeac5..87c81851d7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -68,7 +68,7 @@ public class FragmentBase extends Fragment { } protected void finish() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); else finish = true; diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 336030a6dd..58fb0d8872 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -749,7 +749,7 @@ public class FragmentCompose extends FragmentBase { activity.runOnUiThread(new Runnable() { @Override public void run() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) checkInternet(); } }); @@ -806,7 +806,7 @@ public class FragmentCompose extends FragmentBase { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) onExit(); return true; case R.id.menu_zoom: @@ -3307,7 +3307,7 @@ public class FragmentCompose extends FragmentBase { private ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() { @Override public boolean onBackPressed() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) onExit(); return true; } diff --git a/app/src/main/java/eu/faircode/email/FragmentFolder.java b/app/src/main/java/eu/faircode/email/FragmentFolder.java index 2b5324bd10..4cb008bc78 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolder.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolder.java @@ -255,7 +255,7 @@ public class FragmentFolder extends FragmentBase { } }); onSave(false); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); break; @@ -478,7 +478,7 @@ public class FragmentFolder extends FragmentBase { ask.setArguments(aargs); ask.setTargetFragment(FragmentFolder.this, REQUEST_SAVE_CHANGES); ask.show(getFragmentManager(), "folder:save"); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } @@ -519,7 +519,7 @@ public class FragmentFolder extends FragmentBase { @Override protected void onExecuted(Bundle args, Void data) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 991b908278..4bedb6e38d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -785,7 +785,7 @@ public class FragmentIdentity extends FragmentBase { fragment.setArguments(aargs); fragment.setTargetFragment(FragmentIdentity.this, REQUEST_SAVE); fragment.show(getFragmentManager(), "identity:save"); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } @@ -1058,7 +1058,7 @@ public class FragmentIdentity extends FragmentBase { } }); onSave(false); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); break; case REQUEST_DELETE: @@ -1109,7 +1109,7 @@ public class FragmentIdentity extends FragmentBase { @Override protected void onExecuted(Bundle args, Void data) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index e06ca7195e..2fb726f8b7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2254,7 +2254,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. activity.runOnUiThread(new Runnable() { @Override public void run() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) adapter.checkInternet(); } }); @@ -2525,7 +2525,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void onMenuFolders(long account) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack("unified", 0); Bundle args = new Bundle(); @@ -2773,7 +2773,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override public void onException(@NonNull Throwable ex) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (ex instanceof IllegalStateException) { Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG); snackbar.setAction(R.string.title_fix, new View.OnClickListener() { @@ -3075,7 +3075,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void navigate(long id, final boolean left) { - if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return; Bundle args = new Bundle(); @@ -3094,7 +3094,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. return; } - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE); getArguments().putBoolean("fade", true); @@ -3337,7 +3337,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { String action = intent.getAction(); if (ACTION_STORE_RAW.equals(action)) @@ -4376,7 +4376,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. return; } - if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) manager.popBackStack("search", FragmentManager.POP_BACK_STACK_INCLUSIVE); Bundle args = new Bundle(); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 3f4b403ec6..9801da5aaf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -254,7 +254,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre activity.runOnUiThread(new Runnable() { @Override public void run() { - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { ConnectionHelper.NetworkState networkState = ConnectionHelper.getNetworkState(getContext()); tvConnectionType.setText(networkState.isUnmetered() ? R.string.title_legend_unmetered : R.string.title_legend_metered); diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java index 4379870fd6..4807bae18f 100644 --- a/app/src/main/java/eu/faircode/email/SimpleTask.java +++ b/app/src/main/java/eu/faircode/email/SimpleTask.java @@ -122,17 +122,17 @@ public abstract class SimpleTask implements LifecycleObserver { if (state.equals(Lifecycle.State.DESTROYED)) { // No delivery cleanup(context); - } else if (state.isAtLeast(Lifecycle.State.RESUMED)) { + } else if (state.isAtLeast(Lifecycle.State.STARTED)) { // Inline delivery Log.i("Deliver task " + name); deliver(); cleanup(context); } else owner.getLifecycle().addObserver(new LifecycleObserver() { - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - public void onResume() { + @OnLifecycleEvent(Lifecycle.Event.ON_START) + public void onStart() { // Deferred delivery - Log.i("Resume task " + name); + Log.i("Deferred delivery task " + name); owner.getLifecycle().removeObserver(this); deliver(); cleanup(context); @@ -141,7 +141,7 @@ public abstract class SimpleTask implements LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { // No delivery - Log.i("Destroy task " + name); + Log.i("Destroyed task " + name); owner.getLifecycle().removeObserver(this); cleanup(context); } diff --git a/app/src/main/java/eu/faircode/email/TwoStateOwner.java b/app/src/main/java/eu/faircode/email/TwoStateOwner.java index 9bbad3e84e..4c78031ff9 100644 --- a/app/src/main/java/eu/faircode/email/TwoStateOwner.java +++ b/app/src/main/java/eu/faircode/email/TwoStateOwner.java @@ -26,6 +26,8 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleRegistry; import androidx.lifecycle.OnLifecycleEvent; +// This class can be used as an externally controlled standalone or child life cycle owner + public class TwoStateOwner implements LifecycleOwner { private String name; private LifecycleRegistry registry; @@ -66,15 +68,13 @@ public class TwoStateOwner implements LifecycleOwner { } void start() { - registry.setCurrentState(Lifecycle.State.STARTED); - } - - void resume() { - registry.setCurrentState(Lifecycle.State.RESUMED); + if (!registry.getCurrentState().equals(Lifecycle.State.DESTROYED)) + registry.setCurrentState(Lifecycle.State.STARTED); } void stop() { - registry.setCurrentState(Lifecycle.State.CREATED); + if (!registry.getCurrentState().equals(Lifecycle.State.DESTROYED)) + registry.setCurrentState(Lifecycle.State.CREATED); } void restart() {