关闭

[置顶] Android 关闭与当前应用相关的进程、服务

1917人阅读 评论(0) 收藏 举报

介绍一个很好用的函数,可关闭与当前应用相关的应用、进程、服务。

使用此函数时会发送 ACTION_PACKAGE_RESTARTED广播
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
manager.restartPackage(getPackageName());


需要配置文件中添加权限:
<uses-permission android:name="android.permission.RESTART_PACKAGES"></uses-permission>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>

函数说明:
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.

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4443次
    • 积分:107
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类