开发者

Android Thread & ASynTask

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 AsyncTasks 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜