Gerardo
Gerardo

Reputation: 5830

Android Services

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

Upvotes: 1

Views: 234

Answers (3)

Andy
Andy

Reputation: 780

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

Upvotes: 1

Adrian Fâciu
Adrian Fâciu

Reputation: 12552

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.

Upvotes: 0

CaseyB
CaseyB

Reputation: 25060

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.

Upvotes: 3

Related Questions