Hedu911
Hedu911

Reputation: 133

run a thread behind activities in android

Im developing for an android aplication and I need to run a thread in the background that is going to be check the current gps and show an activity depending of the current location data but the application have diferents activities, and I need this thread running all the time no matter if I change between an activity and other. Can I do that ? I know that I can add threads to an activity but I dont know how have a main thread in the background

Upvotes: 0

Views: 105

Answers (2)

bclymer
bclymer

Reputation: 6771

You want to use a service here:

http://developer.android.com/reference/android/app/Service.html

You can run things in a background thread if you want in the service. And then you can bind to it within your activites to communicate between the service and activities.

Upvotes: 1

Julian Suarez
Julian Suarez

Reputation: 4521

You need to use a Service which is not tied to any particular Activity. You can read all about Services here

In your case I ssuggest you take a look at IntentService which automatically generates a background thread for you

Upvotes: 1

Related Questions