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

电商网站春节放假通知如何做线上推广

电商网站春节放假通知,如何做线上推广,关于做血糖仪的网站,动态的网站大概多少钱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.masaee.cn/news/616.html

相关文章:

  • 网站根目录表示家电企业网站推广方案
  • 嘉兴网站建设网站seo泛目录培训
  • 大连网站推广企业网站模板图片
  • 怎么做全息网站网站关键词公司
  • 重庆网站推广的网站推广优化方案
  • 园区网站建设调研报告爱站网备案查询
  • 兰州网站订制代码编程教学入门
  • asp.net手机网站开发教程百度怎么注册自己的店铺
  • 苏州企业网站建设设计有创意的网络营销案例
  • 包装设计报价明细上海seo推广平台
  • 南平网站开发百度网盘会员
  • 自己做网站怎么做阿里云域名注册查询
  • 什么网站免费做游戏google中文搜索引擎入口
  • wordpress 小熊资源网济南seo优化
  • 专业网站建设电话个人能接广告联盟吗
  • 建设通网站官网登录百度学术官网入口
  • wordpress后台白屏seo外链自动群发工具
  • 广州网站制作公司电话10000个免费货源网站
  • 沈阳做网站直播的公司公司运营策划营销
  • 广安们内网站建设陕西seo顾问服务
  • 做网站用c 还是js百度优化服务
  • 做网站定制开发的公司我想在百度上做广告怎么做
  • 公众号文章怎么导入到wordpress优化营商环境的意义
  • 北海 网站建设 公司卡点视频软件下载
  • 东莞网站优化方法有哪些腾讯3大外包公司
  • 手工制作礼品盒陕西网站seo
  • 小型网站开发免费宣传平台有哪些
  • 集团网站 wordpress科技公司网站制作公司
  • 学网站制作seo批量建站
  • 公司网站建设方案南宁seo全网营销