-2

我正在寻找一种以编程方式清理 android 最近应用程序列表的方法。按下“2 个叠加框”按钮时弹出的列表。

有没有人对我有想法或提示,我该怎么做?

背景是,我开发了一个小应用程序,一个要求是,在“安全模式”下,列表必须为空。我的想法是在关机时清理列表。

谢谢,安德烈

4

1 回答 1

0

Just for your curiosity yeah its possible, But It's a very bad decision since the user might not want his/her important task to be killed.

List<ApplicationInfo> packages;
    PackageManager pm;
    pm = getPackageManager();
    //get a list of installed apps.
    packages = pm.getInstalledApplications(0);

    ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);

   for (ApplicationInfo packageInfo : packages) {
        if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
        if(packageInfo.packageName.equals("mypackage")) continue;
        mActivityManager.killBackgroundProcesses(packageInfo.packageName);
   }
于 2015-08-03T20:11:05.127 回答