zoukankan      html  css  js  c++  java
  • android:强制关闭其他应用

    强制关闭其他应用,可以使用ActivityManager,首先需要获取(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

    然后可以调用其函数来进行关闭操作,目前来看有两种方法:

    1. void killBackgroundProcesses(String packageName):此方法在android官网的API中有介绍,在kill之后,被关闭的应用会被重新启动。

    Have the system immediately kill all background processes associated with the given package.  This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.

    使用:需要权限:<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

    2. void forceStopPackage(String packageName):此方法目前没有出现在android官网的API中,不知为何啊。。。。。。

    使用:

         需要权限:android:sharedUserId="android.uid.system"

          <uses-permission android:name="android.permission.FOCE_STOP_PACKAGES" />

    自己实现的代码:

    ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    activityManager.forceStopPackage("com.android.scan");

    推荐使用第2种。。。。。。。。。。。。。

    参考:http://blog.csdn.net/huxueyan521/article/details/8921976

             http://blog.csdn.net/mingli198611/article/details/7057615

  • 相关阅读:
    JS/JQuery下拉列表选中项的索引
    数据挖掘
    Sencha安装
    新的开始
    jquery multi scrollable 同步的问题
    dom4j
    rest
    spring 2
    spring framework3.0开发
    笔记Spring in action
  • 原文地址:https://www.cnblogs.com/luow/p/3885349.html
Copyright © 2011-2022 走看看