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

网站建设公司有哪些主要内容组成怎么seo网站关键词优化

网站建设公司有哪些主要内容组成,怎么seo网站关键词优化,怎么做网站推广,支付宝小程序搭建WakefulBroadcastReceiver 是一种特殊类型的广播接收器,为应用创建和管理 PARTIAL_WAKE_LOCK 。 简单来说, WakefulBroadcastReceiver 是持有系统唤醒锁的 BroadcastReceiver ,用于执行需要保持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.dinnco.com/news/60047.html

相关文章:

  • 做文案策划需要知道些什么网站友情链接的形式有哪些
  • 六盘水网站设计网络营销战略的内容
  • php自适应网站开发网站优化排名公司哪家好
  • 直接做的黄页视频网站做销售有什么技巧和方法
  • 简单企业网站源码 asp.net 公司介绍 产品展示郑州网络推广方法
  • 杭州做网站外包公司有哪些站外推广渠道
  • 展示型企业网站代写文案平台
  • 政府机关网站制作百度网盘搜索
  • 重庆多功能网站建设国际购物网站平台有哪些
  • 免费安装app百度刷排名seo软件
  • 如何自己做资源网站电商平台推广
  • 如何做哟个优惠券网站扬州网络推广哪家好
  • 天津 网站建设淘宝如何提升关键词排名
  • 北京网站建设的服务百度快速收录网站
  • 对招聘网站页面设计做建议员工培训课程
  • 网站对比分析软文发稿公司
  • php网站开发 招聘seo搜索引擎优化步骤
  • 在线制作仿真证件生成器河南网站推广优化排名
  • 微网站建站系统源码网站排名英文
  • php动态网站开发实例教程书优化手机流畅度的软件
  • 嘉兴有哪些做网站的公司seo关键词优化工具
  • 哈尔滨网页设计模板网站百度网站优化排名
  • 苏州电子商务网站建设桔子seo查询
  • 模板网站建设哪家好互联网公司排名2021
  • app公司网站建设搜狗seo快速排名公司
  • 好看手机网站推荐google关键词seo
  • 手机网站多少钱一个北京seo网站推广
  • 做网站项目的意义ppt介绍最近热点新闻事件
  • 网站违规词处罚做网站的网站服务器速度对seo有什么影响
  • b站直播能禁止id观看吗怎么开一个网站平台