I’m building an android application which uses gps to locate the user. I have a class called LocationService which extends Service and implements LocationListener. In my activity I have the following code. When I want to turn on the service and listen for locations, I call the startLocationService() method. All this is working fine.
I then put this activity in a tab in a tabhost. Now when I call startLocationService(), nothing happens, the onCreate() method in LocationService is not even called. I checked the “this” reference in the line
Intent i = new Intent(this, LocationService.class);
and it refers to the correct activity, not the TabActivity.
I’m at a loss to explain why LocationService is not being started. I’d appreciate any light anyone can shed on this.
thanks,
Paul
private LocationService service = null;
private ServiceConnection svcConn = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
service = (LocationService)binder;
try {
service.registerCallback(cbListener);
service.enableProximityPoints();
} catch (Throwable t) {
Log.e("MyPath", "Exception in call to registerAccount()", t);
}
}
public void onServiceDisconnected(ComponentName className) {
service = null;
}
};
private void startLocationService(){
Intent i = new Intent(this, LocationService.class);
bindService(i, svcConn, 0);
startService(i);
}
Looks like someone else has had a similar problem: http://www.mail-archive.com/android-beginners@googlegroups.com/msg08047.html
They solved their problem by moving the service connection up into the TabActivity class.