From 986d6386ed5f1e4a29bf44e109ea946bf059ba57 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Tue, 8 Mar 2016 14:41:48 -0300 Subject: [PATCH] Add method to destroy the singleton Calling AppRate.destroy() ensures that the context has no references and can be freed if needed. Also add LeakCanary on the sample application to ensure that the memory leak was fixed. --- .../main/java/hotchemi/android/rate/AppRate.java | 4 ++++ sample/build.gradle | 4 ++++ sample/src/main/AndroidManifest.xml | 2 ++ .../android/rate/sample/ExampleApplication.java | 13 +++++++++++++ .../hotchemi/android/rate/sample/MainActivity.java | 5 +++++ 5 files changed, 28 insertions(+) create mode 100644 sample/src/main/java/hotchemi/android/rate/sample/ExampleApplication.java diff --git a/library/src/main/java/hotchemi/android/rate/AppRate.java b/library/src/main/java/hotchemi/android/rate/AppRate.java index 16e9fb5..e3fd844 100644 --- a/library/src/main/java/hotchemi/android/rate/AppRate.java +++ b/library/src/main/java/hotchemi/android/rate/AppRate.java @@ -53,6 +53,10 @@ public static AppRate with(Context context) { return singleton; } + public static void destroy() { + singleton = null; + } + public static boolean showRateDialogIfMeetsConditions(Activity activity) { boolean isMeetsConditions = singleton.isDebug || singleton.shouldShowRateDialog(); if (isMeetsConditions) { diff --git a/sample/build.gradle b/sample/build.gradle index 740fb6f..6fffd60 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -24,4 +24,8 @@ repositories { dependencies { compile project(':library') + // Leak detection + debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' + releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' + testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' } \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index cabd2eb..b221b53 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -5,10 +5,12 @@ diff --git a/sample/src/main/java/hotchemi/android/rate/sample/ExampleApplication.java b/sample/src/main/java/hotchemi/android/rate/sample/ExampleApplication.java new file mode 100644 index 0000000..2f171f2 --- /dev/null +++ b/sample/src/main/java/hotchemi/android/rate/sample/ExampleApplication.java @@ -0,0 +1,13 @@ +package hotchemi.android.rate.sample; + +import android.app.Application; + +import com.squareup.leakcanary.LeakCanary; + +public class ExampleApplication extends Application { + @Override + public void onCreate() { + super.onCreate(); + LeakCanary.install(this); + } +} diff --git a/sample/src/main/java/hotchemi/android/rate/sample/MainActivity.java b/sample/src/main/java/hotchemi/android/rate/sample/MainActivity.java index 1d02eb2..1580f1e 100644 --- a/sample/src/main/java/hotchemi/android/rate/sample/MainActivity.java +++ b/sample/src/main/java/hotchemi/android/rate/sample/MainActivity.java @@ -37,4 +37,9 @@ public void onClickButton(int which) { AppRate.showRateDialogIfMeetsConditions(this); } + @Override + protected void onDestroy() { + AppRate.destroy(); + super.onDestroy(); + } } \ No newline at end of file