Reputation: 155
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
This is coming from my Service (GetInformationService.onConnected). It is weird how it says it is not connected in my onConnected method? I have seen many questions like this but I could still not figure it out because all of the answers say something about onCreate method but I have no onCreate since this is a service. Here is my relevant code (keep in mind I am extending IntentService):
@Override
protected void onHandleIntent(Intent intent)
{
g = Globals.getInstance();
context = this;
locationProvider = LocationServices.FusedLocationApi;
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
locationRequest = new LocationRequest();
locationRequest.setInterval(60000);
locationRequest.setFastestInterval(15000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
googleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle)
{
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
Upvotes: 0
Views: 282
Reputation: 7348
Try including onCreate()
in your service and build googApiClient
from here
@Override
public void onCreate() {
super.onCreate();
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
}
Upvotes: 2