From a65591287e5d6166c89a8ec7eb69d350b591abb1 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 5 Jan 2019 07:59:32 +0000 Subject: [PATCH] MLDB: store the application instance in the context variable avoids a warning about storing activity/fragment instances in static variables, which may lead to leaks --- app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index e4304060..4446427f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -18,6 +18,7 @@ package net.ktnx.mobileledger.utils; import android.annotation.TargetApi; +import android.app.Application; import android.content.Context; import android.content.res.Resources; import android.database.Cursor; @@ -47,7 +48,7 @@ public final class MLDB { public static final String OPT_TRANSACTION_LIST_STAMP = "transaction_list_last_update"; public static final String OPT_LAST_REFRESH = "last_refresh"; private static MobileLedgerDatabase helperForReading, helperForWriting; - private static Context context; + private static Application context; private static void checkState() { if (context == null) throw new IllegalStateException("First call init with a valid context"); @@ -160,6 +161,7 @@ public final class MLDB { } return c; + } }; @@ -167,8 +169,8 @@ public final class MLDB { view.setAdapter(adapter); } - public static void init(Context context) { - MLDB.context = context.getApplicationContext(); + public static void init(Application context) { + MLDB.context = context; } public static void done() { if (helperForReading != null) -- 2.39.5