From 38a5ca656c423c063277bd9feabcbf783c71bf48 Mon Sep 17 00:00:00 2001 From: Joshua Soberg Date: Wed, 3 Feb 2021 21:51:44 -0500 Subject: [PATCH] #635 - Use a lifecycle observer to cancel an active task when going to the background if set to do so --- .../andotp/Activities/AuthenticateActivity.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java index a219f0a6..0c1a975b 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java @@ -32,6 +32,9 @@ import com.google.android.material.textfield.TextInputLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; +import androidx.lifecycle.DefaultLifecycleObserver; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.ProcessLifecycleOwner; import android.text.Editable; import android.text.InputType; @@ -106,6 +109,9 @@ public class AuthenticateActivity extends BaseActivity } }); + ProcessLifecycleOwner.get().getLifecycle() + .addObserver(new ProcessLifecycleObserver()); + getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } @@ -195,6 +201,15 @@ public class AuthenticateActivity extends BaseActivity unlockProgress.setVisibility(isTaskRunning ? View.VISIBLE : View.GONE); } + private class ProcessLifecycleObserver implements DefaultLifecycleObserver { + @Override + public void onStop(LifecycleOwner owner) { + if (settings.getRelockOnBackground()) { + cancelBackgroundTask(); + } + } + } + @Override public void onClick(View view) { Editable text = passwordInput.getText();