alarm

自己的alarm学习笔记

alarm的主要工作流程分为以下三步:

1.APP获取服务

2.AlarmService和AlarmManger交互

3.Alarm通过广播,或activity,service通知APP


1.应用分析:

接下来可以写一个安卓测试demo来测试:

AlarmManager alarmmanager = (AlarmManager)getSystemService(ALARM_SERVICE); //第一步,获取服务,当然也就包含了第二步(AlarmService和AlarmManger交互,那是系统的事情了)
        
        PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(this, ActionBroadCast.class), Intent.FLAG_ACTIVITY_NEW_TASK); //绑定广播</span>
        long now = System.currentTimeMillis();  
        setInexactRepeating(AlarmManager.RTC_WAKEUP, now, 3000, pi);//参考这里http://www.android-doc.com/reference/android/app/AlarmManager.html

 
 @Override  
    public void onReceive(Context context, Intent intent) { <span style="font-family: Arial, Helvetica, sans-serif;">//第三步,注册广播,等待系统通知</span>
        // TODO Auto-generated method stub  
        Log.e("ActionBroadCast", "New Message !" + num++);  
    }  
intervalMillisinterval in milliseconds between subsequent repeats of the alarm. Prior to API 19, if this is one of INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY, or INTERVAL_DAY then the alarm will be phase-aligned with other alarms to reduce the number of wakeups. Otherwise, the alarm will be set as though the application had called setRepeating(int, long, long, PendingIntent). As of API 19, all repeating alarms will be inexact and subject to batching with other alarms regardless of their stated repeat interval.
 
<span style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif;  background-color: rgb(249, 249, 249);"><em><span style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif;  background-color: rgb(249, 249, 249);"><em><span style="font-size:14px;">operation                <span style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif; background-color: rgb(249, 249, 249);">Action to perform when the alarm goes off; typically comes from </span><code style="color: rgb(0, 102, 0); font-stretch: normal; line-height: 14px; margin-bottom: 0px; background-color: rgb(249, 249, 249);"><a target=_blank href="http://www.android-doc.com/reference/android/app/PendingIntent.html#getBroadcast(android.content.Context, int, android.content.Intent, int)" style="color: rgb(37, 138, 175); text-decoration: none; margin-bottom: 0px;">IntentSender.getBroadcast()</a></code><span style="color: rgb(34, 34, 34); font-family: Roboto, sans-serif; background-color: rgb(249, 249, 249);">.</span></span></em></span></em></span>



2.框架分析:

Alarm在安卓系统中主要分为如下几层:


框架中的主要调用流程如下:






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值