SystemUI下的RecentActivity

我们接着研究下SystemUI下的RecentActivity:
这个类就是用来清除当前正在使用的应用程序的。。。
去找那个清除按钮事件,看看调用了什么方法:
首先获取final ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);ActivityManager实例
然后final List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();获取当前的应用进程信息
然后是一个for来循环去清楚应用进程。
最后获取最近的任务信息队列:
final List<ActivityManager.RecentTaskInfo> recentTasks =
                        am.getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), 
                            ActivityManager.RECENT_IGNORE_UNAVAILABLE);
通过for循环将他们从队列中移除。


这里让我想到了之前的一个问题?android4.0之后Service会随着app的结束而结束,我们怎么样才能让我们的Service一直运行在后台呢?就像QQ一样?


我们通过这个来找找有没有什么办法?
if ((sr.serviceInfo.flags&ServiceInfo.FLAG_STOP_WITH_TASK) != 0) {
                    Slog.i(TAG, "Stopping service " + sr.shortName + ": remove task");
                    stopServiceLocked(sr);
}
这里就是清除和App相关的Service的代码?
这里有个属性可以注意下(sr.serviceInfo.flags&ServiceInfo.FLAG_STOP_WITH_TASK) != 0 什么情况下可以避免这个条件成立。
/**
     * Bit in {@link #flags}: If set, the service will automatically be
     * stopped by the system if the user removes a task that is rooted
     * in one of the application's activities.  Set from the
     * {@link android.R.attr#stopWithTask} attribute.
     */
    public static final int FLAG_STOP_WITH_TASK = 0x0001;


    /**
     * Bit in {@link #flags}: If set, the service will run in its own
     * isolated process.  Set from the
     * {@link android.R.attr#isolatedProcess} attribute.
     */
    public static final int FLAG_ISOLATED_PROCESS = 0x0002;


    /**
     * Bit in {@link #flags}: If set, a single instance of the service will
     * run for all users on the device.  Set from the
     * {@link android.R.attr#singleUser} attribute.
     */
    public static final int FLAG_SINGLE_USER = 0x40000000;


似乎只要设置这个属性为FLAG_ISOLATED_PROCESS就能够避免被清楚,真的是这样嘛?只有试试才知道!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值