Вопрос

is it possible to fire up an event at a specified time interval in BlackBerry? I'm looking for something similar to AlarmManager class in Android (if anyone is familiar with it).

The goal is to is to run some code, even when the application is not in foreground and without it gaining foreground "focus". Preferably it should be possible to fire the event even if the app was killed by system or by phone reboot (I do not know the details about killing apps at this OS, I'm beginning development now).

I would prefer not to write a background process for this task as it is going to be fired every few hours (I think it would be a waste of battery to use a background task for a simple alarm-like event).

I've looked around a lot, but I cannot find any satisfying solution.

cheers,

kajman

Это было полезно?

Решение

The Timer and TimerTask classes are useful for running a task on a schedule. Take a look at the APIs here:

http://www.blackberry.com/developers/docs/7.0.0api/java/util/Timer.html

The Timer will create its own Thread and sleep until it has a task to run. It would involve having a background task running but it wouldn't be using an CPU or battery if it is just waiting.

If you don't want a Thread running all of the time you can use the ApplicationManager class to schedule your application to start later.

You can also configure your app to run on start up. The OS generally won't kill your apps unless you have a coding error. RIM refers to this as the Always-On Experience in their Super App document:

http://docs.blackberry.com/en/developers/deliverables/23567/Always_on_1380986_11.jsp#Keeping_the_app_running_1381022_11

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top