开发者

Launch activity at certain time

I'm new to Android development, so I might be missing something obvious. I want to launch an Activity when the user's phone clock hits a specified time (similar to an alarm). However, I'm not sure how I would go about doing this as constant polling of the clock seems inefficient and a waste of re开发者_开发问答sources. Do I need to capture broadcast events from the clock, or use PendingIntents? If someone could point out some SDK methods/services I should read about, it would be much appreciated. Thanks.


Take a look at the docs for android.app.AlarmManager.

This class allows your application to schedule PendingIntents for broadcast at specific times, which sounds like exactly what you're looking for. Just schedule a PendingIntent that launches the desired application.

Be aware that when your alarm fires, the phone will be prevented from sleeping until (and only until) onReceive() finishes executing. If you need to keep the phone awake longer, you may need to implement your own wake lock.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜