#635 - Use a lifecycle observer to cancel an active task when going to the background if set to do so

This commit is contained in:
Joshua Soberg 2021-02-03 21:51:44 -05:00
parent 97e7f51fe9
commit 38a5ca656c

View file

@ -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();