重新启动应用程序,有两种方法,分别是:

1.通过ActivityManager来重新启动应用程序:

ActivityManager manager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
manager.restartPackage(“com.example.test”);

2.通过flag来实现:

private void restartApplication() {
        final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

}

3.重新启动系统的方法有:

 

PowerManager manager = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
manager.reboot(“重新启动系统”)

4:

/**
* 重启应用
* @param context
*/
public static void restartApp(Context context){
final Intent intent = context.getPackageManager().getLaunchIntentForPackage((CommonClass.APP_NAME));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}