Skip to content

Commit 841fb4c

Browse files
authored
Merge pull request #6495 from danielmbutler/Replace-System.exit-calls
Replace the System.exit calls with getActivity.finishAffinity()
2 parents 2de9d7b + 90de759 commit 841fb4c

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/ExitActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.os.Build;
77
import android.os.Bundle;
88

9+
import org.schabi.newpipe.util.NavigationHelper;
10+
911
/*
1012
* Copyright (C) Hans-Christoph Steiner 2016 <hans@eds.org>
1113
* ExitActivity.java is part of NewPipe.
@@ -48,6 +50,6 @@ protected void onCreate(final Bundle savedInstanceState) {
4850
finish();
4951
}
5052

51-
System.exit(0);
53+
NavigationHelper.restartApp(this);
5254
}
5355
}

app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.schabi.newpipe.extractor.localization.ContentCountry;
2828
import org.schabi.newpipe.extractor.localization.Localization;
2929
import org.schabi.newpipe.streams.io.StoredFileHelper;
30+
import org.schabi.newpipe.util.NavigationHelper;
3031
import org.schabi.newpipe.util.ZipHelper;
3132

3233
import java.io.File;
@@ -255,7 +256,7 @@ private void finishImport() {
255256
// save import path only on success; save immediately because app is about to exit
256257
saveLastImportExportDataUri(true);
257258
// restart app to properly load db
258-
System.exit(0);
259+
NavigationHelper.restartApp(requireActivity());
259260
}
260261

261262
private Uri getImportExportDataUri() {

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,16 @@ public static void playWithKore(final Context context, final Uri videoURL) {
600600
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
601601
context.startActivity(intent);
602602
}
603+
604+
/**
605+
* Finish this <code>Activity</code> as well as all <code>Activities</code> running below it
606+
* and then start <code>MainActivity</code>.
607+
*
608+
* @param activity the activity to finish
609+
*/
610+
public static void restartApp(final Activity activity) {
611+
activity.finishAffinity();
612+
final Intent intent = new Intent(activity, MainActivity.class);
613+
activity.startActivity(intent);
614+
}
603615
}

0 commit comments

Comments
 (0)