0

I am trying to implement the android developers Geofence sample as a background service in my application. I want to convert the GeoActivity to a service. How can I do that...Or is there any way to run this activity in background and having another activity running in the foreground??

the code is in: http://developer.android.com/training/location/geofencing.html

user1901079
  • 427
  • 2
  • 7
  • 19

1 Answers1

0

Make a separate class which extends Service and implement geofence insertion there.

public class BackgroundService extends Service{
 your geofence insertion logic here....
}

Now from any other Activity call startService method which takes an intent as argument.

It could be as :

public class MainActivity extends Activity{
Intent backgroundService;
backgroundService = new Intent(this, BackgroundService.class);
startService(backgroundService);

}

Dont forget to declare the service as child of your application in your manifest.

Sabih
  • 11
  • 1