Skip to content

Commit

Permalink
Merge pull request #6495 from danielmbutler/Replace-System.exit-calls
Browse files Browse the repository at this point in the history
Replace the System.exit calls with getActivity.finishAffinity()
  • Loading branch information
Stypox authored Jun 17, 2021
2 parents 2de9d7b + 90de759 commit 841fb4c
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 @@ -600,4 +600,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 841fb4c

Please sign in to comment.