android 关于提高第三方app的service优先级
本博客仅仅要没有注明“转”。那么均为原创,转贴请注明本博客链接链接
基本上大家都知道提高service优先级能够在非常大程度上让你的service免于由于内存不足而被kill,当然系统仅仅是在此时先把优先级低的kill掉。假设内存还是不够,也会把你的service干掉的。只是如今的机器不像几年前了,基本上不会发生那种情况。
先来看看网上常见的错误方法:
1.android:persistent="true"
对第三方app无效,以下是官方说明
android:persistent
- Whether or not the application should remain running at all times — "
true
" if it should, and "false
" if not. The default value is "false
". Applications should not normally set this flag; persistence mode is intended only for certain system applications.
2.onDestroy中重新启动service
service被系统杀死的时候并不一定会运行onDestroy。拿什么重新启动
3.android:priority
service根本没有这属性
4.setForeground
这个是有效的,可是网上的样例却都是无效的原因是參数错误
让service免于非难的办法是提高它的重要性,在官方文档中已经说明进程有五个级别,当中前台进程最重要。所以最后被杀死。
怎样使之变成前台进程能够參阅官方文档。
http://developer.android.com/guide/components/processes-and-threads.html
http://su1216.iteye.com/blog/1591699
这里仅仅说怎样使用setForeground将service设置为前台进程
Notification notification = new Notification();
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
service.startForeground(1, notification);
上面的三个属性放到一起,值为0x62。
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if this notification is in reference to something that is ongoing,
* like a phone call. It should not be set if this notification is in
* reference to something that happened at a particular point in time,
* like a missed phone call.
*/
public static final int FLAG_ONGOING_EVENT = 0x00000002;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if the notification should not be canceled when the user clicks
* the Clear all button.
*/
public static final int FLAG_NO_CLEAR = 0x00000020; /**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if this notification represents a currently running service. This
* will normally be set for you by {@link Service#startForeground}.
*/
public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
最后。我们能够使用以下命令看看手机中的哪些应用这么干了,你在平时使用的时候是不是他们存活时间最长。最不easy被系统干掉
dumpsys notification
转贴请保留以下链接
本人blog地址
android 关于提高第三方app的service优先级的更多相关文章
- [转]android 如何获取第三方app的sha1值
对于android 应用的sha1值和md5值的获取,如果是我们自己的应用,不论是获取测试的和正式的都是比较方便的.但是如何去获取别人开发的app的sha1和md5呢,并且我们只有apk有没有相关的文 ...
- Android开发-实现第三方APP跳转
自己创建一个按钮: <Button android:id="@+id/btn_button" android:layout_width="fill_parent&q ...
- Android 四大组件之再论service
service常见的有2种方式,本地service以及remote service. 这2种的生命周期,同activity的通信方式等,都不相同. 关于这2种service如何使用,这里不做介绍,只是 ...
- Android开发之通过Intent启动其他App的Service
在Android5.0以前可以通过隐式Intent方式启动其他App的Service,就跟Activity启动隐式Intent一样的. 但是在5.0以后,只能使用显示的Intent方式启动了. 启动其 ...
- 微信授权登陆接入第三方App(步骤总结)Android
微信授权登陆接入第三方App(步骤总结)Android Android App实现第三方微信登录
- android -------- 打开本地浏览器或指定浏览器加载,打电话,打开第三方app
开发中常常有打开本地浏览器加载url或者指定浏览器加载, 还有打开第三方app, 如 打开高德地图 百度地图等 在Android程序中我们可以通过发送隐式Intent来启动系统默认的浏览器. 如果手机 ...
- Android高效率编码-第三方SDK详解系列(二)——Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能
Android高效率编码-第三方SDK详解系列(二)--Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能 我的本意是第二篇写Mob的shareSD ...
- Android高效率编码-第三方SDK详解系列(三)——JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送
Android高效率编码-第三方SDK详解系列(三)--JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送 很久没有更新第三方SDK这个系列了,所以更新一下这几天工作中使用到的推送, ...
- Android高效率编码-第三方SDK详解系列(一)——百度地图,绘制,覆盖物,导航,定位,细腻分解!
Android高效率编码-第三方SDK详解系列(一)--百度地图,绘制,覆盖物,导航,定位,细腻分解! 这是一个系列,但是我也不确定具体会更新多少期,最近很忙,主要还是效率的问题,所以一些有效的东西还 ...
随机推荐
- HDU 1247 Hat’s Words
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- POJ 2481 Cows
Cows Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16546 Accepted: 5531 Description ...
- C/C++面试小知识点
1.static有什么用途. 解答: 在函数体中,一个被声明为静态的变量在这一函数被调用过程中维持其值不变. 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所有函数访问,但不能被模块外其 ...
- HDU 4405-Aeroplane chess(概率dp)
题意: n+1格飞行棋,编号0-n,从0格开始,每次扔一个色子,得到的点数就向前走几步,但有有些格子到达后可以直接飞到后面的格子, 当到达>=n的地方结束,求结束扔色子的期望次数. 分析: dp ...
- word编号库中找不到带圈编号“①②③......"了怎么办?
进入“Word选项/语言”对话框: 找到“朝鲜语”并将它添加到编辑语言的列表框中,无需设置为启用状态或默认编辑语言: 退出并重新启动Word: 再次打开“定义新编号格式”对话框则可以在“编号样式”下拉 ...
- DbContext运行时动态附加上一个dbset
参考 Creating DbSet Properties Dynamically C# code? 1 DbSet<MyEntity> set = context.Set<MyEnt ...
- Fitnesse-20140630与RestFixture-3.1编译与运行步骤
为了能使RestFixture-3.1在Fitnesse-20140630中正确打印测试结果,准备修改RestFixture. 1.下载并编译Fitnesse-20140630 以下步骤以在64位Wi ...
- ORA-15018: diskgroup cannot be created
创建ASM磁盘组的时候出错,具体报错如下: SQL> create diskgroup kel external redundancy disk 'ORCL:KEL1','ORCL:KEL2'; ...
- sensor BMA250源代码执行分析
重力传感器是根据压电效应的原理来工作的. 所谓的压电效应就是 “对于不存在对称中心的异极晶体加在晶体上的外力除了使晶体发生形变以外,还将改变晶体的极化状态,在晶体内部建立电场,这种由于机械力作用使 ...
- Linux之一次性安装开发工具:yum groupinstall Development tools
[spark@sparksinglenode ~]$ yum grouplist | moreLoaded plugins: fastestmirror, refresh-packagekit, se ...