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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -