开发者

Android Services, Threads and UI

开发者 https://www.devze.com 2023-03-31 22:39 出处:网络
I have a ListActivity that starts a service. In this service, I started a thread that does some database query of up to 800 contacts, this seems to be slowing down or even hanging the UI sometimes. Sh

I have a ListActivity that starts a service. In this service, I started a thread that does some database query of up to 800 contacts, this seems to be slowing down or even hanging the UI sometimes. Should I开发者_JAVA技巧 be using AsyncTask instead? What is the proper way to handle this?


Normally services are running on UI-Thread. But you had mentioned that you are using thread in services it mean your work is doing in background so there is no any possibility to block UI-Thread.

I think you had write a some code out of thread for update UI and that may be blocking your UI.

You can use AsyncTask instead of starting service and updating using thread because asynctask is doing same thing as background thread can do.


Try incremental load of the contacts for your list. Querying so much data would of course slow your thread down.

0

精彩评论

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

关注公众号