[size=large]测试定时事件不太容易,比如要测试 AlarmManager 中定时明天4点的一个事件,你总不能等到明天4点再看看吧。
Roman Nurik 提供了两个用来测试定时事件的命令:[color=darkred]adb shell dumpsys alarm [/color]和 [color=darkred]adb shell dumpsys activity intents [/color]通过这两个命令可以查看那些操作被放到定时队列中了。
例如,要查看你的应用都定时执行那些任务,通过命令 ‘adb shell dumpsys alarm’,在结果中查找你的应用包名,结果看起来如下:
RTC #6: Alarm{434a1378 type 1 com.example}
type=1 whenElapsed=608198149 when=+52m27s736ms window=-1 repeatInterval=0 count=0
operation=PendingIntent{430cf620: PendingIntentRecord{*43bbf998* com.example startService}}
上面的结果显示一个事件将在大约 52 分钟后触发。要查看该 intent 的详细信息 (例如 启动的是那个 service?)则需要用到 ‘adb shell dumpsys activity intents’ 命令,查看结果中和 PendingIntentRecord 的 id 一样的结果(上面示例中的 id 为 43bbf998):
* PendingIntentRecord{43bbf998 com.example startService}
uid=10138 packageName=com.example type=startService flags=0×0
requestIntent=act=MY_ACTION cmp=com.example/.MyService (has extras)[/size]
转载自:[url]http://blog.chengyunfeng.com/?p=561[/url]
Roman Nurik 提供了两个用来测试定时事件的命令:[color=darkred]adb shell dumpsys alarm [/color]和 [color=darkred]adb shell dumpsys activity intents [/color]通过这两个命令可以查看那些操作被放到定时队列中了。
例如,要查看你的应用都定时执行那些任务,通过命令 ‘adb shell dumpsys alarm’,在结果中查找你的应用包名,结果看起来如下:
RTC #6: Alarm{434a1378 type 1 com.example}
type=1 whenElapsed=608198149 when=+52m27s736ms window=-1 repeatInterval=0 count=0
operation=PendingIntent{430cf620: PendingIntentRecord{*43bbf998* com.example startService}}
上面的结果显示一个事件将在大约 52 分钟后触发。要查看该 intent 的详细信息 (例如 启动的是那个 service?)则需要用到 ‘adb shell dumpsys activity intents’ 命令,查看结果中和 PendingIntentRecord 的 id 一样的结果(上面示例中的 id 为 43bbf998):
* PendingIntentRecord{43bbf998 com.example startService}
uid=10138 packageName=com.example type=startService flags=0×0
requestIntent=act=MY_ACTION cmp=com.example/.MyService (has extras)[/size]
转载自:[url]http://blog.chengyunfeng.com/?p=561[/url]
本文介绍使用adb命令测试Android应用中的定时任务方法。通过dumpsys alarm和dumpsys activity intents命令,可以查看已安排的AlarmManager事件及其详细信息。
9276

被折叠的 条评论
为什么被折叠?



