Reputation: 133
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
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
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