Android彻底关闭当前应用


以下方法用于关闭当前应用:

ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
manager.restartPackage(getPackageName());

需要权限:
"Android.permission.RESTART_PACKAGES"

函数说明:
void android.app.ActivityManager.restartPackage(String packageName)

public void restartPackage (String packageName)
Since: API Level 3

Have the system perform a force stop of everything associated with the given application package. All processes that share its uid will be killed, all services it has running stopped, all activities removed, etc. In addition, a ACTION_PACKAGE_RESTARTED broadcast will be sent, so that any of its registered alarms can be stopped, notifications removed, etc.

You must hold the permission RESTART_PACKAGES to be able to call this method.
Parameters
packageName     The name of the package to be stopped.

与当前应用相关的应用、进程、服务等也会被关闭。
会发送 ACTION_PACKAGE_RESTARTED广播。
不要被函数名误导。

相关内容