GoogleApiClient is throwing "GoogleApiClient is not connected yet" AFTER onConnected function getting called

Solution 1:

I just noticed that you are creating the googleApiClient in onStartCommand(). This seems like a bad idea.

Let's say that your service gets triggered twice. Two googleApiClient objects will get created, but you'll only have reference to one. If the one whose reference you don't have executes its callback to onConnected(), you will be connected in that client but the client whose reference you actually do have could still be unconnected.

I suspect that's what's going on. Try moving your googleApiClient creation to onCreate and see if you get the same behavior.

Solution 2:

I had the same error, but my problem was different from iheanyl's answer:

I had declared the googleApiClient static. This prevented android from shutting down the service.