下面列出了android.app.ActivityManager#restartPackage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 退出应用程序
*
* @param context 上下文
* @param isBackground 是否开开启后台运行
*/
public void AppExit(Context context, Boolean isBackground) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
} catch (Exception e) {
} finally {
// 注意,如果您有后台程序运行,请不要支持此句子
if (!isBackground) {
System.exit(0);
}
}
}
/**
* 退出应用程序
*
* @param context 上下文
* @param isBackground 是否开开启后台运行
*/
public void AppExit(Context context, Boolean isBackground) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
} catch (Exception e) {
} finally {
// 注意,如果您有后台程序运行,请不要支持此句子
if (!isBackground) {
System.exit(0);
}
}
}
/**
* 退出应用程序
*
* @param context 上下文
* @param isBackground 是否开开启后台运行
*/
public void AppExit(Context context, Boolean isBackground) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
} catch (Exception e) {
} finally {
// 注意,如果您有后台程序运行,请不要支持此句子
if (!isBackground) {
System.exit(0);
}
}
}
/**
* 退出应用程序
*
* @param isBackground 是否开开启后台运行
*/
public void exitApp(Boolean isBackground) {
try {
finishAllActivity();
ActivityManager activityMgr =
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(mContext.getPackageName());
} catch (Exception e) {
FL.e(TAG, FL.getExceptionString(e));
} finally {
// 注意,如果您有后台程序运行,请不要支持此句子
if (!isBackground) {
System.exit(0);
}
}
}
/**
* 释放手机内存,清理缓存 <功能简述>
*
* @param context
*/
public static void releaseMemory(Context context) {
ActivityManager activityManger = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> list = activityManger
.getRunningAppProcesses();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
ActivityManager.RunningAppProcessInfo apinfo = list.get(i);
String[] pkgList = apinfo.pkgList;
if (apinfo.importance > ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE
&& !apinfo.processName.equals("com.tt.realeasememory")) {
for (int j = 0; j < pkgList.length; j++) {
if (Build.VERSION.SDK_INT >= 8) {
activityManger.killBackgroundProcesses(pkgList[j]);
} else {
activityManger.restartPackage(pkgList[j]);
}
}
}
}
}
}
/**
* 退出应用程序
*
* @param context
*/
public void AppExit(Context context) {
finishAllActivity();
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// // 2.2之前的rom就用restartPackage之后的就用killBackgroundProcesses
if (BaseApplication.isMethodsCompat(Build.VERSION_CODES.FROYO)) {
activityManager.killBackgroundProcesses(context.getPackageName());
} else {
activityManager.restartPackage(context.getPackageName());
}
System.exit(0);
}
/**
* 退出应用程序
*/
@SuppressWarnings("deprecation")
public void AppExit(Context context) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) {
}
}
public static void AppExit(Context context) {
try {
finishAllActivity();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) {
}
}
public void AppExit(Context context) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) {
}
}
/**
* 退出应用程序
*/
public void exitWholeApp(Context context) {
try {
finishAllActivity();
ActivityManager activityMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Exit the application.
*
* @param context given context
*/
public void AppExit(Context context) {
try {
finishAllActivities();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context
.ACTIVITY_SERVICE);
activityManager.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}