android - async task for step counter? to periodically calling async task -
at first, step counter.
my initial structure service keeps logging step counter value database.
async task keeps updating value shown user when app visible user.
planed create thread periodically call async task.
however, after digging official document, "async task should created , invoked within ui thread".
conflict ui thread should not blocked vs calling async task periodically.
or there else better way implement?
input.
you need derive asynctask
inside ui class (service or activity).
inside asynctask (as described here) there doinbackground
runs asynchronously , there onpostexecute
runs inside ui thread after asynchronous task over.
just put db operation inside doinbackground
, put inside onpostexecute
myserviceclass.this.runnexttask();
the runnexttask
method in ui class use same asynctask
launch next task.
Comments
Post a Comment