APP重启功能实现

方式一:使用AlarmManger

Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
 //与正常页面跳转一样可传递序列化数据,在Launch页面内获得
intent.putExtra("REBOOT","reboot");
 PendingIntent restartIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
 AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
 mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent);
 android.os.Process.killProcess(android.os.Process.myPid());

方式二:通过设置FLAG_ACTIVITY_CLEAR_TOP

Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//与正常页面跳转一样可传递序列化数据,在Launch页面内获得
intent.putExtra("REBOOT","reboot");
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/qq_35416214/article/details/106767960