make K9PreferenceActivity implement LifecycleOwner
package com.fsck.k9.activity;
+
+import android.arch.lifecycle.Lifecycle;
+import android.arch.lifecycle.Lifecycle.State;
+import android.arch.lifecycle.LifecycleOwner;
+import android.arch.lifecycle.LifecycleRegistry;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.support.annotation.NonNull;
import com.fsck.k9.K9;
-public abstract class K9PreferenceActivity extends PreferenceActivity {
+public abstract class K9PreferenceActivity extends PreferenceActivity implements LifecycleOwner {
+ private LifecycleRegistry lifecycleRegistry;
+
@Override
public void onCreate(Bundle icicle) {
K9ActivityCommon.setLanguage(this, K9.getK9Language());
setTheme(K9.getK9ThemeResourceId());
super.onCreate(icicle);
+ lifecycleRegistry = new LifecycleRegistry(this);
+ lifecycleRegistry.markState(State.CREATED);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ lifecycleRegistry.markState(State.STARTED);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ lifecycleRegistry.markState(State.RESUMED);
+ }
+
+ @Override
+ protected void onPause() {
+ lifecycleRegistry.markState(State.STARTED);
+ super.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ lifecycleRegistry.markState(State.CREATED);
+ super.onStop();
+ }
+
+ @Override
+ protected void onDestroy() {
+ lifecycleRegistry.markState(State.DESTROYED);
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ // see https://developer.android.com/topic/libraries/architecture/lifecycle.html#onStop-and-savedState
+ lifecycleRegistry.markState(State.CREATED);
+ super.onSaveInstanceState(outState);
+ }
+
+ @NonNull
+ @Override
+ public Lifecycle getLifecycle() {
+ return lifecycleRegistry;
}
/**
