+
+ private void restartPrivacyBrowser() {
+ // Create an intent to restart Privacy Browser.
+ Intent restartIntent = requireActivity().getParentActivityIntent();
+
+ // Assert that the intent is not null to remove the lint error below.
+ assert restartIntent != null;
+
+ // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
+ restartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+
+ // Create a handler to restart the activity.
+ Handler restartHandler = new Handler(Looper.getMainLooper());
+
+ // Create a runnable to restart the activity.
+ Runnable restartRunnable = () -> {
+ // Restart the activity.
+ startActivity(restartIntent);
+
+ // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
+ System.exit(0);
+ };
+
+ // Restart the activity after 200 milliseconds, so that the app has enough time to save the change to the preference.
+ restartHandler.postDelayed(restartRunnable, 200);
+ }