views:

63

answers:

3

Hi,

i have a question. I'm developing an Android Application. Actually, i have a thread in background that makes request to an external API in order to get data when the users clicks in different parts of the app. My doubt is if this "thread" would be better if i implemented it as a service instead of a Runnable class.

Thanks

+3  A: 

The point of a service is that it can run while your app is not resident. If you only want the service to run while your app is open then a thread is the probably the best way to do it.

CaseyB
great, so i continue using the thread. thanks
xger86x
A: 

If your information can be used by any other application you could use a service or as they are called in Android, a Content Provider. This way you make the information available to all the applications on the phone. This is a great way of encouraging other developers to build their applications with the info that you've provided. This is just something that you should consider, if it's something strictly related to you're application you can go on with the thread just as CaseyB stated.

Adrian Faciu
ok, i go with the thread. Content Provider i think is not necessary to my ap. thanks
xger86x
+1  A: 

As i learned some days ago, using AsyncTasks is the preferred, painless way in android to do background tasks. Have a look here to get a good tutorial.

http://android-developers.blogspot.com/2009/05/painless-threading.html

bye

Andy