I want to implement the thread in my application
first requirement is:
Each activity access the local database that time it take some time to load.So I am planning to give progress-dialog.I want to do it in thread.Currently I did usin开发者_JAVA技巧g the AsynsTask
because of I dodnt know how long will take for record. Other than AsynsTask
How we can implement using Thread?
Multitasking Facility :
I want to run two activity.One is in background.I.E If there are any upload available(Database Syn Android to SQL Server) while running activity ,Upload should start in background.How we can implement this?
Please guide me on this
Thanks in advance
You want to synchronize your database in background so I think you have to use service
in which you have to implement thread
and you have to write your code in thread.
You can then schedule your service startup time
and also you can repeat your service
when ever you want to keep duration for start service.
And for upload you have to options
1) Using AysncTask
2) Using Service with thread
And also know that Service is running in main UI so if you want to use service for synchronize database you have to implement thread
you can execute many AsyncTask
s in the background, but only one Activity
can be active at a single time.
AsyncTask
handles the threading for you.
In your case, AysncTask
has one benefit, that when multi-user (other word, multi connection) connect to database, AsyncTask
will do in serial. (But you should notice, this might change through android version, for example: at Donut, they will do together, but in Honeycomb to now, serially)
精彩评论