Maurice
Maurice

Reputation: 6433

Android Services, Threads and UI

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 be using AsyncTask instead? What is the proper way to handle this?

Upvotes: 1

Views: 336

Answers (2)

Kumar Bibek
Kumar Bibek

Reputation: 9117

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

Upvotes: 0

Dharmendra
Dharmendra

Reputation: 33996

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.

Upvotes: 1

Related Questions