android提高进程优先级的若干方法

转载自:http://www.2cto.com/kf/201402/279086.html,在此表示感谢

方法1: 提高进程优先级 startForeground(1, new Notification()); 降低进程优先级 stopForeground(true); 

onStart() 方法中进行提高优先级操作,然后在onStop()方法中进行降低优先级操作
这个方法可以将对应AP的ADJ临时提高到2。

方法2
找到这个进程对应的 Android Mannifest.xml文件,在其中添加属性『android:persistent="true"』, 这样可以将该进程设置为常驻内存进程,就可以降低被Kill的概率。以Acore进程为例, 在 /package/providers/ContactsProvider/AndroidMannifest.xml 文件中增加一行『android:persistent="true"』
具体修改示例如下:
<application android:process="android.process.acore"
android:label="@string/app_label"
android:icon="@drawable/app_icon"
android:allowBackup="false"
android:persistent="true" 
方法3:
在需要提高优先级的地方调用: 
final Intent it = new Intent(); 
it.setAction("android.intent.action.BOOST_DOWNLOADING"); 
it.putExtra("package_name", "com.android.contacts"); 
it.putExtra("enabled",  true); 
context.sendBroadcast(it); 
在需要恢复到正常优先级时调用: 
final Intent it = new Intent(); 
it.setAction("android.intent.action.BOOST_DOWNLOADING"); 
it.putExtra("package_name", "com.android.contacts"); 
it.putExtra("enabled",  false); 
context.sendBroadcast(it); 
onStart() 方法中进行提高优先级操作,然后在onStop()方法中进行降低优先级操作
这个方法可以将对应AP的ADJ临时提高到7。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值