From the GooglePlayServicesClient.ConnectionCallbacks documentation onDisconnected should get called when the LocationClient is disconnected. From my testing I noticed it never gets called if I disconnect the LocationClient myself.
Here is the most basic sample code I have.
public class MainActivity extends ActionBarActivity implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
private LocationClient locationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationClient = new LocationClient(getApplicationContext(), this, this);
locationClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
Log.d("APP", "Location Client Connected");
locationClient.disconnect();
Log.d("APP", "Client is connected " + locationClient.isConnected());
}
@Override
public void onDisconnected() {
Log.d("APP", "Location Client Disconnected");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d("APP", "Location Client connect failed");
}
}
I received the onConnected() callback but never the onDisconnected() callback. In the onConnected callback where I print out the connected status of the client, it properly prints out "false".
Am I misunderstanding something or is the onDisconnected callback only called by external events such as:
- activity/service shutdown
- location client becomes unavailable
I was stuck with the same issue and found an answer here: