Android中提高后台服务进程优先级的方法
来源:互联网 发布:ubuntu登录密码忘记了 编辑:程序博客网 时间:2024/05/21 09:50
后台服务进程不能在状态栏显示通知,所以优先级相对比较低,在内存不足的时候比较容易被系统杀掉,提高进程的优先级可以降低被杀的概率。
大致思路是:1.启动一个空的服务;
2.先设置一个前台通知,然后再取消通知
代码如下:
public class EmptyService extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub try { if (Daemonservice.contextReference != null) { //to improve service prioty start ((Service) Daemonservice.contextReference.get()).startForeground(1, new Notification()); super.startForeground(1, new Notification()); ((Service) Daemonservice.contextReference.get()).stopForeground(true); //to improve service prioty end } return START_NOT_STICKY; } catch (Exception e) { return START_NOT_STICKY; } }}
注:这里的Daemonservice.contextReference 是一个弱引用,在其他类中定义的静态类变量,如下所示:
public static WeakReference<Context> contextReference ;
0 0
- Android中提高后台服务进程优先级的方法
- Android提高后台服务进程优先级
- Android 中提高后台服务优先级
- Android中提高进程优先级的方法策略
- android提高进程优先级的方法
- android提高进程优先级的方法
- android提高进程优先级的若干方法
- android 提高进程的优先级
- android 提高进程的优先级
- Android进阶之进程优先级及提高优先级的方法(Service进程防杀死)
- Android进程提高优先级
- Android基础总结——进程优先级及提高优先级的方法
- Android 进程优先级及提高优先级的方法(Service尽量不死之法)
- 提高进程的优先级
- Android中进程的优先级
- 提高Android Service 优先级的方法
- 提高Android Service 优先级的方法 .
- Android基础总结——进程优先级及提高优先级的方法(Service尽量不死之法)
- intellij的tomcat工作目录问题
- 跨域
- 打开 Eclipse 报错信息Failed to load the JNI shared library jvm.dll
- android开发摄像头开发,在自己的SurfaceView里预览,并且解决摄像头预览变形问题--懒人笔记02
- JMeter录制脚本方法
- Android中提高后台服务进程优先级的方法
- Performance Optimization of UITableView
- yield(C# 参考)
- AngularJS入门(7)-Angular过滤器
- spring mvc定时器的使用
- hadoop-2.7.3源码编译
- js提交数组对象备份
- 接口
- linux-C编程-进程间通信