当前位置: 首页 > news >正文

长沙好的网站建设公司企业展厅设计公司虎

长沙好的网站建设公司,企业展厅设计公司虎,网站建设选用平台分析,网站开发登录要做哪些验证WakefulBroadcastReceiver 是一种特殊类型的广播接收器#xff0c;为应用创建和管理 PARTIAL_WAKE_LOCK 。 简单来说#xff0c; WakefulBroadcastReceiver 是持有系统唤醒锁的 BroadcastReceiver #xff0c;用于执行需要保持CPU运转的场景。 注册 注册 Receiver #…WakefulBroadcastReceiver 是一种特殊类型的广播接收器为应用创建和管理 PARTIAL_WAKE_LOCK 。 简单来说 WakefulBroadcastReceiver 是持有系统唤醒锁的 BroadcastReceiver 用于执行需要保持CPU运转的场景。 注册 注册 Receiver receiver android:name.MyWakefulReceiver/receiver实现MyWakefulReceiver 重写 onReceive() 方法使用 startWakefulService(Context context, Intent intent) 启动 Service public class MyWakefulReceiver extends WakefulBroadcastReceiver {Overridepublic void onReceive(Context context, Intent intent) {// Start the service, keeping the device awake while the service is// launching. This is the Intent to deliver to the service.Intent service new Intent(context, MyIntentService.class);startWakefulService(context, service);}} Service Service 里执行正常的逻辑实行结束后调用 MyWakefulReceiver.completeWakefulIntent(Intent intent) 方法。 public class MyIntentService extends IntentService {public MyIntentService() {super(MyIntentService);}Overrideprotected void onHandleIntent(Intent intent) {Bundle extras intent.getExtras();// Do the work that requires your app to keep the CPU running.// ...// Release the wake lock provided by the WakefulBroadcastReceiver.MyWakefulReceiver.completeWakefulIntent(intent);} }源码分析 在 startWakefulService(Context context, Intent intent) 方法中通过 PowerManager.WakeLock 持有了系统锁并为每个 intent 设置了一个 id 用于标识存储在 sActiveWakeLocks 数组中 /*** Do a {link android.content.Context#startService(android.content.Intent)* Context.startService}, but holding a wake lock while the service starts.* This will modify the Intent to hold an extra identifying the wake lock;* when the service receives it in {link android.app.Service#onStartCommand* Service.onStartCommand}, it should pass back the Intent it receives there to* {link #completeWakefulIntent(android.content.Intent)} in order to release* the wake lock.** param context The Context in which it operate.* param intent The Intent with which to start the service, as per* {link android.content.Context#startService(android.content.Intent)* Context.startService}.*/public static ComponentName startWakefulService(Context context, Intent intent) {synchronized (sActiveWakeLocks) {int id mNextId;mNextId;if (mNextId 0) {mNextId 1;}intent.putExtra(EXTRA_WAKE_LOCK_ID, id);ComponentName comp context.startService(intent);if (comp null) {return null;}PowerManager pm (PowerManager)context.getSystemService(Context.POWER_SERVICE);PowerManager.WakeLock wl pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,androidx.core:wake: comp.flattenToShortString());wl.setReferenceCounted(false);wl.acquire(60 * 1000);sActiveWakeLocks.put(id, wl);return comp;}}当 Service 调用 MyWakefulReceiver.completeWakefulIntent(Intent intent) 方法时释放系统锁并根据 id 将此锁从数组中移除 /*** Finish the execution from a previous {link #startWakefulService}. Any wake lock* that was being held will now be released.** param intent The Intent as originally generated by {link #startWakefulService}.* return Returns true if the intent is associated with a wake lock that is* now released; returns false if there was no wake lock specified for it.*/public static boolean completeWakefulIntent(Intent intent) {final int id intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0);if (id 0) {return false;}synchronized (sActiveWakeLocks) {PowerManager.WakeLock wl sActiveWakeLocks.get(id);if (wl ! null) {wl.release();sActiveWakeLocks.remove(id);return true;}// We return true whether or not we actually found the wake lock// the return code is defined to indicate whether the Intent contained// an identifier for a wake lock that it was supposed to match.// We just log a warning here if there is no wake lock found, which could// happen for example if this function is called twice on the same// intent or the process is killed and restarted before processing the intent.Log.w(WakefulBroadcastReceiv., No active wake lock id # id);return true;}}
http://www.huolong8.cn/news/211065/

相关文章:

  • 做托福的网站怎样重新运行wordpress
  • 建设文明网站包括19
  • asp开发网站详细步骤做设计网站的工作内容
  • 网站建设咨询什么宿州高端网站建设公司哪家好
  • 网站建设推广案例c 转网站开发
  • 网站代码怎么看网站开发 硬件环境
  • 公司企业网站设计尺寸网站建设的企业目标
  • 搜索引擎站长平台云南官网制作
  • 做网站需要了解什么漳州微信网站开发
  • 八年级信技做网站网站建设客户资源
  • 注册网站需要多少钱手机端怎么变成电脑端
  • 外国网站建设公司中国河北网站
  • 建设银行网站打不井工作室有专门的网站
  • 阿里巴巴国际站首页网站主机与服务器
  • 建立网站找什么公司狮山镇建设局网站
  • 做游戏视频网站要批证吗新闻式软文经典案例
  • 手机网站建设平台wordpress 作品主题
  • 建立门户网站多少钱无锡新区网站制作
  • 衡水做网站的地方德安县建设局网站
  • 建设vip网站相关视频下载wordpress实现翻页效果
  • 手机网站设计技巧松山湖网站建设
  • 做暖暖小视频免费网站网站建设玖金手指花总
  • 关于网站建设的调查报告做营销的一般逛哪些网站
  • 企业网站源码推荐网络营销和推广的方法
  • 长沙做网站微联讯点很好简洁大气网站模板
  • 服装购物网站排名wordpress 管理界面
  • 上海手机网站开发价格7月8月带孩子适合去哪里旅游
  • 北京 设计 网站建设自己公司内网网站和外网怎么做同步
  • 网站管理员可控的关键节点网站建设发布设需求
  • 北京做网站公司 seoWordPress付费会员主题