- 浏览: 868311 次
- 性别:
- 来自: 北京
最新评论
-
luna_2006:
...
【Java】枚举类型Enum介绍和方法详解 -
沙漠孤影:
...
【Android】Android Market 链接的生成与分享 -
sjl_008:
有错误,inSampleSize 为2时,图片大小不是原来的2 ...
【Android】如何解决bitmap 内存溢出out of memory的问题 -
huanglei_jay:
【Java】Collections.EMPTY_LIST和Collections.emptyList()简单使用心得 -
wuxuewujiang:
很详细!很有用的整理。
【Objective-C】NSDate详解及获取当前时间等常用操作
对应AlarmManage有一个AlarmManagerServie服务程 序,该服务程序才是正真提供闹铃服务的,它主要维护应用程序注册下来的各类闹铃并适时的设置即将触发的闹铃给闹铃设备(在系统中,linux实现的设备名 为”/dev/alarm”),并且一直监听闹铃设备,一旦有闹铃触发或者是闹铃事件发生,AlarmManagerServie服务程序就会遍历闹铃列 表找到相应的注册闹铃并发出广播。该服务程序在系统启动时被系统服务程序system_service启动并初始化闹铃设备(/dev/alarm)。当 然,在JAVA层的AlarmManagerService与Linux Alarm驱动程序接口之间还有一层封装,那就是JNI。
AlarmManager将应用与服务分割开来后,使得应用程序开发者不用 关心具体的服务,而是直接通过AlarmManager来使用这种服务。这也许就是客户/服务模式的好处吧。AlarmManager与 AlarmManagerServie之间是通过Binder来通信的,他们之间是多对一的关系。
在android系统中,AlarmManage提供了3个接口5种类型的闹铃服务。
3个接口:
- // 取消已经注册的与参数匹配的闹铃
- void cancel(PendingIntent operation)
- //注册一个新的闹铃
- void set( int type, long triggerAtTime, PendingIntent operation)
- //注册一个重复类型的闹铃
- void setRepeating( int type, long triggerAtTime, long interval, PendingIntent operation)
- //设置时区
- void setTimeZone(String timeZone)
- // 取消已经注册的与参数匹配的闹铃
- void cancel(PendingIntent operation)
- //注册一个新的闹铃
- void set(int type, long triggerAtTime, PendingIntent operation)
- //注册一个重复类型的闹铃
- void setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)
- //设置时区
- void setTimeZone(String timeZone)
5个闹铃类型
- public static final int ELAPSED_REALTIME
- // 当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是相对时间,是从系统启动后开始计时的,包括睡眠时 间,可以通过调用SystemClock.elapsedRealtime()获得。系统值是3 (0x00000003)。
- public static final int ELAPSED_REALTIME_WAKEUP
- //能唤醒系统,用法同ELAPSED_REALTIME,系统值是2 (0x00000002) 。
- public static final int RTC
- //当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是绝对时间,所用时间是UTC时间,可以通过调用 System.currentTimeMillis()获得。系统值是1 (0x00000001) 。
- public static final int RTC_WAKEUP
- //能唤醒系统,用法同RTC类型,系统值为 0 (0x00000000) 。
- Public static final int POWER_OFF_WAKEUP
- //能唤醒系统,它是一种关机闹铃,就是说设备在关机状态下也可以唤醒系统,所以我们把它称之为关机闹铃。使用方法同RTC类型,系统值为4(0x00000004)。
- public
- static final int ELAPSED_REALTIME
- //当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是相对时间,是从系统启动后开始计时的,包括睡眠
- 时间,可以通过调用SystemClock.elapsedRealtime()获得。系统值是3 (0x00000003)。
- public static final int ELAPSED_REALTIME_WAKEUP
- //能唤醒系统,用法同ELAPSED_REALTIME,系统值是2 (0x00000002) 。
- public static final int RTC
- //当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是绝对时间,所用时间是UTC时间,可以通过调用
- System.currentTimeMillis()获得。系统值是1 (0x00000001) 。
- public static final int RTC_WAKEUP
- //能唤醒系统,用法同RTC类型,系统值为 0 (0x00000000) 。
- Public static final int POWER_OFF_WAKEUP
- //能唤醒系统,它是一种关机闹铃,就是说设备在关机状态下也可以唤醒系统,所以我们把它称之为关机闹铃。使用方法同RTC类型,系统值为
- 4(0x00000004)。
注意一个重要的参数PendingIntent。这个PendingIntent可以说是 Intent的进一步封装,他既包含了Intent的描述又是Intent行为的执行(这种定义也许不太严格),如果将Intent比作成一个订单的 话,PendingIntent更像是一个下订单的人,因为它既要负责将订单发出去,也要负责订单发送后的处理,比如发送成功后要准备验收订单货物,发送 失败后要重发还是取消订单等操作。开发者可以通过调用getActivity(Context, int, Intent, int)
getBroadcast(Context, int, Intent, int)
getService(Context, int, Intent, int)
三种不同方式来得到一个PendingIntent实例。
getBroadcast——通过该函数获得的PendingIntent将会 扮演一个广播的功能,就像调用 Context.sendBroadcast()函数一样。当系统通过它要发送一个intent时要采用广播的形式,并且在该intent中会包含相应的 intent接收对象,当然这个对象我们可以在创建PendingIntent的时候指定,也可以通过ACTION 和CATEGORY等描述让系统自动找到该行为处理对象。
- Intent intent = new Intent(AlarmController. this , OneShotAlarm. class );
- PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this , 0 , intent, 0 );
- Intent intent = new Intent(AlarmController.this, OneShotAlarm.class);
- PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this, 0, intent, 0);
getActivity——通过该函数获得的PendingIntent可以直 接启动新的activity, 就像调用 Context.startActivity(Intent)一样.不过值得注意的是要想这个新的Activity不再是当前进程存在的Activity 时。我们在intent中必须使用Intent.FLAG_ACTIVITY_NEW_TASK.
- // The PendingIntent to launch our activity if the user selects this notification
- PendingIntent contentIntent = PendingIntent.getActivity(this , 0 , new Intent( this , AlarmService. class ), 0 );
- // The PendingIntent to launch our activity if the user selects this notification
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, AlarmService.class), 0);
getService——通过该函数获得的PengdingIntent可以直接启动新的Service,就像调用Context.startService()一样。
- // Create an IntentSender that will launch our service, to be scheduled
- // with the alarm manager.
- mAlarmSender = PendingIntent.getService(AlarmService.this ,
- 0 , new Intent(AlarmService. this , AlarmService_Service. class ), 0 );
发表评论
-
【Android】监听SDCard安装和卸载的代码片段(测试通过)
2012-03-21 18:39 2171// 监听类 private final Bro ... -
【Android】实现XML解析的几种技术
2012-03-16 16:52 3320本文介绍在Android平台中实现对XML的三种 ... -
【Android】AlarmManager简介
2012-03-15 20:15 1980AlarmManager 包含的主要方法: ... -
【Android】this和this.getApplictionContext的区别 (转载)
2012-03-08 15:30 2811在android中常常会遇到与context有关的内容, ... -
【Android】在QQ通讯录,360之前拦截短信(intent-filter的优先级)
2012-06-26 11:28 3349原文:http://www.bangchui.org/sim ... -
【Android】xml文件里面出现unbound prefix的问题
2012-02-06 15:25 39247相信有很多菜鸟在编写xml文件的时候,都会遇 ... -
【Android】模拟器启动不了 emulator: ERROR: unknown virtual device name
2012-02-06 15:24 2995很多人在配置android环境的时候卡了壳,一切准备工作 ... -
【Android】Intent 和 Intent Filter 官方文档读后总结
2012-02-03 17:46 2243Intent 和 Intent Filter 1 ... -
【Android】Intent 和 Intent Filter
2012-02-03 17:42 1400转自:http://www.cnblogs.com/Andro ... -
【Android】常量DEFAULT_KEYS_SHORTCUT 功能的验证 及其 源码实现分析
2012-02-03 17:15 2348转自:http://blog.csdn.net/silence ... -
【Android】Android 手机杀进程并不省电,效果只能适得其反
2011-11-29 11:21 4901大家可能是被windows毒 ... -
【Android】BroadcastReceiver简介和用法实例,两种注册方式 (二)
2011-11-24 10:52 9924一.BroadcastReceiver简介 B ... -
【Android】BroadCastReceiver 简介
2011-11-24 10:50 3713BroadCastReceiver 简介 Bro ... -
【Android】四大组件之Service(服务)
2011-11-24 10:49 2153Service是Andorid系统提供的四大组件之一,它 ... -
【Android】BroadcastReceiver发送intent给service或者activity
2011-11-24 10:46 6935BroadcastReceiver:对象的生命周期不超过5s, ... -
【Android】理解Service和BroadcastReceiver(转载)
2011-11-24 10:45 2390Service与Activity类似,也需要在Manifest ... -
【Android】监听文件和目录的创建删除移动等事件
2011-11-16 10:36 2696出于安全上的需要,我们经常需要监听sd卡或者其他路径上的 ... -
【Android】如何在Activity中启动另一应用程序的方法,无需得到类名
2011-11-16 10:33 3081在网上搜索了一会相关的实现代码,发现所有的文章都说是需要 ... -
【Android】loadData与loadDataWithBaseURL的区别
2011-11-10 13:54 34110在写WebView时,感觉LoadUrl太浪费流量,而且 ... -
【Android】检测手机摇晃
2011-11-10 11:10 4385做游戏的时候,一般都要使用到多种多样的传感器,以实现比较丰 ...
相关推荐
android AlarmManager 多个 定时 重复提醒,我这篇博文的源码。
Android AlarmManager
Andorid AlarmManager的使用,通过这个实例可以变换实现闹钟功能
先说下需求吧, 这个是服务器端设定几个时间段,比如说 周一,周三 的下午15点。 然后让用户来勾选。如果用户选择了这个时间段,那么每个周一,周三的下午15点都给用户一个提醒
Android_AlarmManager一些简单的操作
使用AlarmManager实现Android定时任务(闹钟),解决了Android版本更新导致的定时不准确问题。Demo源码
Android 后台运行 定时器 AlarmManager Service
这篇文章使用AlarmManager实现了Android定时后台循环任务。使用场景:项目需要app每隔一段时间就去服务端请求一次接口,从而更新本地保存的信息。 AlarmManager简介 AlarmManager是Android中常用的一种系统级别的...
android安卓闹铃服务AlarmManager的使用
Android中使用AlarmManager设置闹钟示例代码
AlarmManager提供了访问系统闹钟的服务。它允许你安排你的应用在未来某个时间点运行。这就相当于定时任务。对于少于60s的定时任务,不推荐使用AlarmManager,可以使用更高效的的Handler来处理频发的任务。
Android开发中,alarmManager在5.0以上系统,启动时间设置无效的问题 做一个app,需要后台保持发送心跳包。由于锁屏后CPU休眠,导致心跳包线程被挂起,所以尝试使用alarmManager定时唤醒Service发送心跳包。 以下是...
在Android平台,如何使用AlarmManager启动广播BroeadReceiver 、服务Service 、页面Activity。
AlarmManager实质是一个全局的定时器,是Android中常用的一种系统级别的提示服务,在指定时间或周期性启动其它组件(包括Activity,Service,BroadcastReceiver)。本文将讲解一下如何使用AlarmManager实现定时提醒...
主要介绍了Android开发之AlarmManager的用法,是Android应用开发中非常实用的技能,需要的朋友可以参考下
主要介绍了Android闹铃服务AlarmManager用法,结合实例形式深入分析了闹铃服务AlarmManager的功能、原理、定义与使用方法,需要的朋友可以参考下
Android下AlarmManager的小闹钟程序,初学可以看看
http://blog.csdn.net/two_water/article/details/52004414 博客Demo