diff --git a/app/src/main/java/org/schabi/newpipe/ExitActivity.java b/app/src/main/java/org/schabi/newpipe/ExitActivity.java index d457500aa..8da22db2d 100644 --- a/app/src/main/java/org/schabi/newpipe/ExitActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ExitActivity.java @@ -6,6 +6,8 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; +import org.schabi.newpipe.util.NavigationHelper; + /* * Copyright (C) Hans-Christoph Steiner 2016 * ExitActivity.java is part of NewPipe. @@ -48,6 +50,6 @@ public class ExitActivity extends Activity { finish(); } - System.exit(0); + NavigationHelper.restartApp(this); } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 4ef5b8b25..0ba5fca9c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -27,6 +27,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.streams.io.StoredFileHelper; +import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ZipHelper; import java.io.File; @@ -255,7 +256,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { // save import path only on success; save immediately because app is about to exit saveLastImportExportDataUri(true); // restart app to properly load db - System.exit(0); + NavigationHelper.restartApp(requireActivity()); } private Uri getImportExportDataUri() { 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 106399735..9bf8d25fa 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -599,4 +599,16 @@ public final class NavigationHelper { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } + + /** + * Finish this Activity as well as all Activities running below it + * and then start MainActivity. + * + * @param activity the activity to finish + */ + public static void restartApp(final Activity activity) { + activity.finishAffinity(); + final Intent intent = new Intent(activity, MainActivity.class); + activity.startActivity(intent); + } }