From 61779142131838eaca0ecd2e291fb8b929a88b2a Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 22 Nov 2018 08:13:49 -0800 Subject: [PATCH] add lifecycle lib (events only logged only so far) --- xwords4/android/app/build.gradle | 3 +++ .../java/org/eehouse/android/xw4/XWApp.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 2176ad851..94d68ce0b 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -208,6 +208,9 @@ dependencies { implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-compat:$SUPPORT_LIB_VERSION" + implementation "android.arch.lifecycle:extensions:1.1.1" + annotationProcessor "android.arch.lifecycle:compiler:1.1.1" + // 2.6.8 is probably as far forward as I can go without upping my // min-supported SDK version xw4dImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 15cde5677..307b1230f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -21,6 +21,11 @@ package org.eehouse.android.xw4; import android.app.Application; +import android.arch.lifecycle.Lifecycle; +import android.arch.lifecycle.LifecycleObserver; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.OnLifecycleEvent; +import android.arch.lifecycle.ProcessLifecycleOwner; import android.content.Context; import android.graphics.Color; import android.os.Build; @@ -32,7 +37,9 @@ import java.util.UUID; import junit.framework.Assert; -public class XWApp extends Application { +import static android.arch.lifecycle.Lifecycle.Event.ON_ANY; + +public class XWApp extends Application implements LifecycleObserver { private static final String TAG = XWApp.class.getSimpleName(); public static final boolean BTSUPPORTED = true; @@ -65,6 +72,8 @@ public class XWApp extends Application { Assert.assertTrue( s_context == s_context.getApplicationContext() ); super.onCreate(); + ProcessLifecycleOwner.get().getLifecycle().addObserver(this); + // This one line should always get logged even if logging is // off -- because logging is on by default until logEnable is // called. @@ -91,6 +100,12 @@ public class XWApp extends Application { WiDirWrapper.init( this ); } + @OnLifecycleEvent(ON_ANY) + public void onAny(LifecycleOwner source, Lifecycle.Event event) + { + Log.d( TAG, "onAny(%s, %s)", source, event ); + } + // This is called on emulator only, but good for ensuring no memory leaks // by forcing JNI cleanup @Override