Force restart app after enabling Chromecast

This commit is contained in:
ByteHamster 2020-06-11 23:12:05 +02:00
parent f48c75aa83
commit 2b8e416aae
3 changed files with 15 additions and 10 deletions

View File

@ -1,12 +1,15 @@
package de.danoeh.antennapod;
import android.app.Application;
import android.content.ComponentName;
import android.content.Intent;
import android.os.StrictMode;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeModule;
import com.joanzapata.iconify.fonts.MaterialModule;
import de.danoeh.antennapod.activity.SplashActivity;
import de.danoeh.antennapod.core.ApCoreEventBusIndex;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.spa.SPAUtil;
@ -63,4 +66,12 @@ public class PodcastApp extends Application {
.installDefaultEventBus();
}
public static void forceRestart() {
Intent intent = new Intent(getInstance(), SplashActivity.class);
ComponentName cn = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(cn);
getInstance().startActivity(mainIntent);
Runtime.getRuntime().exit(0);
}
}

View File

@ -3,7 +3,6 @@ package de.danoeh.antennapod.fragment.preferences;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -17,10 +16,10 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import androidx.preference.PreferenceFragmentCompat;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.OpmlImportActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.SplashActivity;
import de.danoeh.antennapod.asynctask.DocumentFileExportWorker;
import de.danoeh.antennapod.asynctask.ExportWorker;
import de.danoeh.antennapod.core.export.ExportWriter;
@ -212,13 +211,7 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
AlertDialog.Builder d = new AlertDialog.Builder(getContext());
d.setMessage(R.string.import_ok);
d.setCancelable(false);
d.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
Intent intent = new Intent(getContext(), SplashActivity.class);
ComponentName cn = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(cn);
startActivity(mainIntent);
Runtime.getRuntime().exit(0);
});
d.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> PodcastApp.forceRestart());
d.show();
}

View File

@ -7,6 +7,7 @@ import androidx.appcompat.app.AlertDialog;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.fragment.preferences.PlaybackPreferencesFragment;
@ -40,7 +41,7 @@ public class PreferenceControllerFlavorHelper {
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(android.R.string.dialog_alert_title);
dialog.setMessage(R.string.pref_restart_required);
dialog.setPositiveButton(android.R.string.ok, null);
dialog.setPositiveButton(android.R.string.ok, (dialog1, which) -> PodcastApp.forceRestart());
dialog.setCancelable(false);
dialog.show();
}