Best method to run a periodic background service in java blackberry -
objective: want develop ui application runs service/ task/method periodically update database. service should start after periodically if application not active/visible/user exits app. similar an android service .
i'm using blackberry java 7.1 sdk eclipse plugin .
the options came across following:
1) how run blackberry application in background
this link suggests extend application
instead of uiapplication
. can't application has user interface.
2) make application go in background
i don't want ui application go in background, instead want application call service periodically .
3) run background task mainscreen in blackberry?
this link suggests run thread, don't think if user exits application thread run in background
4) blackberry install background service ui application?
this suggests using codemodulemanager ,whose usage i'm unable figure .
please suggest best way achieve objective or suggests other better method .
i new blackberry please pardon ignorance.
to expand on peter's answer:
you need create 2 classes :
class bgapp extends applicaton class uiapp extends uiapplication
i guess have created class extends uiapplicaiton. add class extends application.
then create class extends timertask , implement run method call method updates database.
class updatedatabasetask extends timertask
in bgapp constructor, create timer. , schedule
updatedatabasetask
usingschedule(timertask, long, long)
method.define alternate entry points, check "do not show on homescreen" , "auto run on startup" checkboxes bgapp's entry point.
it easiest , simplest use builtin persistence mechanism (
persistentstore
,persistable
interface) storing data. if use other means recordstore or sqldb, both uiapp , bgapp can use access same database. values updated bgapp accessible uiapp , vice-versa, automatically.if want send signal bgapp uiapp (for example when bgapp downloads new data want uiapp reload data instantaneously), post global event (
applicationmanager.postglobalevent()
) when download complete , listen in screen displaying data (globaleventlistener
interface).
there code samples each of these available part of sdk or search on internet , you'll find lot of implementations.
Comments
Post a Comment