Reputation: 95
What is the best way to schedule an event?
I was thinking about the new Calendar API, but it requires an internet connection at least to create a new calendar.
Is there any API for creating a schedule which doesn't require internet connection?
Upvotes: 1
Views: 3203
Reputation: 46856
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 will let you do that.
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);
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.
EDIT: 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"
Upvotes: 5