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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章