Android完全退出应用的方法

退出程序

public static void exitApp(Context context){
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> appTaskList = activityManager.getAppTasks();
    for (ActivityManager.AppTask appTask : appTaskList) {
        appTask.finishAndRemoveTask();
    }
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);
}
 

 重启应用

public static void restartApp(){
    //定时重启
    Intent intent = new Intent(BaseApplication.getAppContext(), MainActivity.class);
    PendingIntent restartIntent = PendingIntent.getActivity(
            BaseApplication.getAppContext(),
            -1,
            intent,
            PendingIntent.FLAG_ONE_SHOT);
    AlarmManager mgr = (AlarmManager) BaseApplication.getAppContext().getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 10 * 1000, restartIntent); 
}

 

posted @ 2018-09-26 11:29  竹下半碗茶  阅读(1631)  评论(0编辑  收藏  举报