-
Notifications
You must be signed in to change notification settings - Fork 803
/
AppExit2Back.java
63 lines (57 loc) · 2.06 KB
/
AppExit2Back.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.jingewenku.abrahamcaijin.commonutil;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import java.util.Timer;
import java.util.TimerTask;
/**
* 主要功能:App应用退出
* @Prject: CommonUtilLibrary
* @Package: com.jingewenku.abrahamcaijin.commonutil
* @author: AbrahamCaiJin
* @date: 2017年05月04日 14:13
* @Copyright: 个人版权所有
* @Company:
* @version: 1.0.0
*/
public class AppExit2Back {
private static Boolean isExit = false;
/**
* 退出App程序应用
* @param context 上下文
* @return boolean True退出|False提示
*/
public static boolean exitApp(Context context) {
Timer tExit = null;
if (isExit == false) {
isExit = true;
//信息提示
AppToastMgr.Toast(context, context.getResources().getString(R.string.sys_exit_tip));
//创建定时器
tExit = new Timer();
//如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
tExit.schedule(new TimerTask() {
@Override
public void run() {
//取消退出
isExit = false;
}
}, 2000);
} else {
AppDavikActivityMgr.getScreenManager().removeAllActivity();
//创建ACTION_MAIN
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Context content = ((Activity) context);
//启动ACTION_MAIN
content.startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
}
AppLogMessageMgr.i("AppExit2Back-->>exitApp", isExit + "");
AppLogMessageMgr.i("AppExit2Back-->>exitApp", "最大内存:" + Runtime.getRuntime().maxMemory());
AppLogMessageMgr.i("AppExit2Back-->>exitApp", "占用内存:" + Runtime.getRuntime().totalMemory());
AppLogMessageMgr.i("AppExit2Back-->>exitApp", "空闲内存:" + Runtime.getRuntime().freeMemory());
return isExit;
}
}