From fda0a550fdbef3d95a1b02b1f469c79c9eebb69e Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 6 Sep 2021 20:47:44 +0200 Subject: [PATCH] Fixed the app restarting not working properly * Using [``process-phoenix``](https://github.com/JakeWharton/ProcessPhoenix) --- app/build.gradle | 3 +++ app/src/main/java/org/schabi/newpipe/App.java | 8 ++++++++ .../main/java/org/schabi/newpipe/about/AboutActivity.kt | 4 ++++ .../java/org/schabi/newpipe/util/NavigationHelper.java | 7 ++++--- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1219aeb33..24ca0426c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -254,6 +254,9 @@ dependencies { // Crash reporting implementation "ch.acra:acra-core:5.7.0" + // Properly restarting + implementation 'com.jakewharton:process-phoenix:2.1.2' + // Reactive extensions for Java VM implementation "io.reactivex.rxjava3:rxjava:3.0.7" implementation "io.reactivex.rxjava3:rxandroid:3.0.0" diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 9f4b6d550..766ebe834 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -11,6 +11,8 @@ import androidx.core.app.NotificationManagerCompat; import androidx.multidex.MultiDexApplication; import androidx.preference.PreferenceManager; +import com.jakewharton.processphoenix.ProcessPhoenix; + import org.acra.ACRA; import org.acra.config.ACRAConfigurationException; import org.acra.config.CoreConfiguration; @@ -86,6 +88,12 @@ public class App extends MultiDexApplication { app = this; + if (ProcessPhoenix.isPhoenixProcess(this)) { + Log.i(TAG, "This is a phoenix process! " + + "Aborting initialization of App[onCreate]"); + return; + } + // Initialize settings first because others inits can use its values NewPipeSettings.initSettings(this); diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt index a18d15af3..a8fdcae26 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt @@ -170,6 +170,10 @@ class AboutActivity : AppCompatActivity() { "PrettyTime", "2012 - 2020", "Lincoln Baxter, III", "https://github.com/ocpsoft/prettytime", StandardLicenses.APACHE2 ), + SoftwareComponent( + "ProcessPhoenix", "2015", "Jake Wharton", + "https://github.com/JakeWharton/ProcessPhoenix", StandardLicenses.APACHE2 + ), SoftwareComponent( "RxAndroid", "2015", "The RxAndroid authors", "https://github.com/ReactiveX/RxAndroid", StandardLicenses.APACHE2 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 eba24020f..1a48b8ed5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -58,6 +58,8 @@ import java.util.ArrayList; import static org.schabi.newpipe.util.external_communication.ShareUtils.installApp; +import com.jakewharton.processphoenix.ProcessPhoenix; + public final class NavigationHelper { public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag"; public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag"; @@ -607,8 +609,7 @@ public final class NavigationHelper { */ public static void restartApp(final Activity activity) { NewPipeDatabase.close(); - activity.finishAffinity(); - final Intent intent = new Intent(activity, MainActivity.class); - activity.startActivity(intent); + + ProcessPhoenix.triggerRebirth(activity.getApplicationContext()); } }