首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android完全封闭应用程序

2012-06-28 
Android完全关闭应用程序在工作过程序中遇到一个需要完全关闭应用程序的问题,在网络上找了一大堆的文章,每

Android完全关闭应用程序

在工作过程序中遇到一个需要完全关闭应用程序的问题,在网络上找了一大堆的文章,每篇都是用System.exit(0)?或者?android.os.Process.killProcess(android.os.Process.myPid())?这两种方法,但是我试过了,?System.exit(0)?这个根本不行,而?android.os.Process.killProcess(android.os.Process.myPid())?这个只能关闭当前的?Activity?,也就是对于一个只有单个?Activity?的应用程序有效,如果对于有多外?Activity?的应用程序它就无能为力了。

/**

* 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 {@link Intent#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 * {@link android.Manifest.permission#RESTART_PACKAGES} to be able to         * call this method.         *         * @param packageName The name of the package to be stopped.         */    public void restartPackage(String packageName) {    try {        ActivityManagerNative.getDefault().restartPackage(packageName);    }    catch (RemoteException e) { }}
??


?

1 楼 newcman 2011-08-26   好像2.2之后的不可以吧~ 2 楼 limingcai 2011-10-25   确实不行,2.2就不行了,虽说2.3了 只有1.6可以

热点排行