参考https://blog.csdn.net/wxd_beijing/article/details/70139239
/**
* 重新启动App -> 杀进程,会短暂黑屏,启动慢
*/
public void restartApp() {
//启动页
Intent intent = new Intent(BaseApplication.instance(), SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
BaseApplication.instance().startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
}
/**
* 重新启动App -> 不杀进程,缓存的东西不清除,启动快
*/
public void restartApp2() {
final Intent intent = BaseApplication.instance().getPackageManager()
.getLaunchIntentForPackage(BaseApplication.instance().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
BaseApplication.instance().startActivity(intent);
}
参考2
https://www.jianshu.com/p/6550b53c6243
最后的实际代码
/**
* 重新启动APP
*/
public static void restartApp(Context context) {
//启动页
Intent LaunchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
LaunchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(LaunchIntent);
}