From 9ca2691a2ca3bf4ac85765552b2085b69e6b590f Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sat, 10 Jul 2021 14:46:51 +0200 Subject: [PATCH] Add close() method to NewPipeDatabase --- .../main/java/org/schabi/newpipe/NewPipeDatabase.java | 11 +++++++++++ .../org/schabi/newpipe/util/NavigationHelper.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java b/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java index 988a5ed98..8f7732218 100644 --- a/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java +++ b/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java @@ -51,4 +51,15 @@ public final class NewPipeDatabase { throw new RuntimeException("Checkpoint was blocked from completing"); } } + + public static void close() { + if (databaseInstance != null) { + synchronized (NewPipeDatabase.class) { + if (databaseInstance != null) { + databaseInstance.close(); + databaseInstance = null; + } + } + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index c35cceb66..67eeb2eb3 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -609,7 +609,7 @@ public final class NavigationHelper { * @param activity the activity to finish */ public static void restartApp(final Activity activity) { - NewPipeDatabase.getInstance(activity).close(); + NewPipeDatabase.close(); activity.finishAffinity(); final Intent intent = new Intent(activity, MainActivity.class); activity.startActivity(intent);