Java Code Examples for android.app.ActivityManager#restartPackage()

The following examples show how to use android.app.ActivityManager#restartPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppManager.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
/**
 * 退出应用程序
 *
 * @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);
        }
    }
}
 
Example 2
Source File: AppManager.java    From KUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 退出应用程序
 *
 * @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);
        }
    }
}
 
Example 3
Source File: AppManager.java    From KUtils-master with Apache License 2.0 6 votes vote down vote up
/**
 * 退出应用程序
 *
 * @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);
        }
    }
}
 
Example 4
Source File: AbsFrame.java    From Aria with Apache License 2.0 6 votes vote down vote up
/**
 * 退出应用程序
 *
 * @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);
    }
  }
}
 
Example 5
Source File: PhoneMemoryUtil.java    From BalloonPerformer with Apache License 2.0 6 votes vote down vote up
/**
 * 释放手机内存,清理缓存 <功能简述>
 * 
 * @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]);
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: AppManager.java    From qingyang with Apache License 2.0 6 votes vote down vote up
/**
 * 退出应用程序
 * 
 * @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);
}
 
Example 7
Source File: AppManager.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 退出应用程序
 */
@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) {
    }
}
 
Example 8
Source File: RxActivityTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
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) {

    }
}
 
Example 9
Source File: AppManager.java    From sealtalk-android with MIT License 5 votes vote down vote up
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) {
    }
}
 
Example 10
Source File: AppManager.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * 退出应用程序
 */
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();
    }
}
 
Example 11
Source File: AppManager.java    From Cotable with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}