在Android中安排活动 [英] Scheduling an event in Android

查看:78
本文介绍了在Android中安排活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安排活动的最佳方式是什么?

What is the best way to schedule an event?

我当时在考虑新的Calendar API,但至少要建立新的日历就需要互联网连接.

I was thinking about the new Calendar API, but it requires an internet connection at least to create a new calendar.

是否有用于创建不需要互联网连接的日程表的API?

Is there any API for creating a schedule which doesn't require internet connection?

推荐答案

查看常见问题解答您更有可能会不断获得如果您回到以前的问题并接受对您有帮助的答案,则有帮助.另请参见如何接受答案?以获取更多信息.

Check out the FAQ You are more likely to keep getting help if you go back to your previous questions and accept answers that were helpful to you. Also see How does accepting an answer work? for more info.

AlarmManager 将使您做到这一点.

如果您想通过处理程序相对较早地安排活动, >是更好的选择.您可以使用它来发布可运行对象,如下所示:

If you want to schedule your event for relatively soon though Handler is a better choice. You can use it to post a runnable like this:

Runnable r = new Runnable() {
    public void run() {
        doSomething();
    }
}
Handler h = new Handler();
h.postDelayed(r, 1000); 

这将在一秒钟内执行您可运行对象的run方法.您可以更改postDelayed方法的第二个参数来更改经过的时间间隔.以毫秒为单位.

This will execute the run method of your runnable in one second. You can change the second parameter of the postDelayed method to change the interval of time that passes. It is in milliseconds.

编辑:还请注意,最佳"做某事的方法是主观的,并且通常取决于您要尝试做的事情.如果您可以更详细地了解您要安排的时间以及要安排的时间,则也许我们可以将其范围缩小到最佳".选择.但是如果没有更多信息,我们将无法告诉您哪个是最佳"

Also note that the "best" way to do something is subjective, and generally depends on exactly what you are trying to do. If you can be more specific about what you are trying to schedule and how far in advance you'd like to schedule it then perhaps we can help narrow it down to the "best" choice. But without more info there is no way that we can tell you which is "best"

这篇关于在Android中安排活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆