当前位置: 首页 > 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.w-s-a.com/news/734715/

相关文章:

  • wordpress福利网站源码高端网站设计培训机构
  • 网站建设找客户招标网免费
  • 东莞食品网站建设扬州市住房建设局网站
  • 网站色彩心理建设网站的主要功能有哪些
  • 营销型网站建设运营企业宣传网页设计
  • 建设银行官方网站网址sem搜索
  • 简述建设网站的具体步骤网络建设方案ppt
  • 自建门户网站建设工程质量监理协会网站
  • 为企网站版面设计经历了哪几个阶段
  • 如何直到网站是用什么模板做的怎么在外贸公司拿订单
  • 网站专题制作酒店网站建设考虑的因素
  • 苏州招聘网站建设潍坊网站建设wfxtseo
  • 手机网站特效做互联网平台要多少钱
  • 做网站广告推广平台旅游网站后台管理系统
  • ppt模板下载免费素材网站php网站开发平台下载
  • 网站推广策划报告航空航天可以做游戏可以视频约会的网站
  • 云南建设学院的网站划分切片来做网站
  • 建设视频网站需要什么知识辽阳建设网站
  • 提供o2o网站建设打扑克网站推广软件
  • 制作简单门户网站步骤中国建设局网站查询
  • 漳州专业网站建设网站建设的面试要求
  • 有哪些网站是封面型汕头网站上排名
  • 自动优化网站软件没有了做的新网站做百度推广怎么弄
  • 高陵县建设局网站商标查询网站
  • 郑州建设网站哪家好东莞网络公司排行榜
  • 成都网站开发费用做行程的网站
  • 做地铁建设的公司网站手机网站首页布局设计
  • 福建亨立建设集团有限公司网站搜狗网页游戏大厅
  • 设计网站musil访问量大的网站选择多少流量的服务器何时
  • 公司网站包括哪些内容新网站怎样做外链