Skip to content

Commit

Permalink
Replaced System.Exit calls with FinishAffinity and Start Activity calls
Browse files Browse the repository at this point in the history
Implemented "RestartApp" method defined in NavigationHelper.java.
 This method is used in ExitActivity.java and ContentSettingsFragment.java
  • Loading branch information
danielmbutler committed Jun 17, 2021
1 parent 547a1a9 commit 8e262f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/org/schabi/newpipe/ExitActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.os.Build;
import android.os.Bundle;

import org.schabi.newpipe.util.NavigationHelper;

/*
* Copyright (C) Hans-Christoph Steiner 2016 <hans@eds.org>
* ExitActivity.java is part of NewPipe.
Expand Down Expand Up @@ -48,6 +50,6 @@ protected void onCreate(final Bundle savedInstanceState) {
finish();
}

System.exit(0);
NavigationHelper.restartApp(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -255,7 +256,7 @@ private void finishImport() {
// 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() {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,16 @@ public static void playWithKore(final Context context, final Uri videoURL) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

/**
* Finish this <code>Activity</code> as well as all <code>Activities</code> running below it
* and then start <code>MainActivity</code>.
*
* @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);
}
}

0 comments on commit 8e262f9

Please sign in to comment.