記一個(gè)小功能重啟app
方式一:使用AlarmManger
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
//與正常頁(yè)面跳轉(zhuǎn)一樣可傳遞序列化數(shù)據(jù),在Launch頁(yè)面內(nèi)獲得
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());
方式二:通過(guò)設(shè)置FLAG_ACTIVITY_CLEAR_TOP
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//與正常頁(yè)面跳轉(zhuǎn)一樣可傳遞序列化數(shù)據(jù),在Launch頁(yè)面內(nèi)獲得
intent.putExtra("REBOOT","reboot");
startActivity(intent);