Google API client does not connect again after onConnectionSuspended (int Cause) is called

I saw this question in the appeal of OnConnecctionSuspended (). stack overflow

I have an activity where I try to track KM sent from the source to the destination when the user presses the start button (start) and then clicks the stop button (Destination). The problem is that it works fine for some 1.5-2 KM, after which the connection is suspended with reason 1, for which the google document says: "CAUSE_SERVICE_DISCONNECTED" - the reason for the suspension informing that the service was killed. According to hounshell's answer , it will automatically try to connect, and we do not need to call the googleApiClient.connect () method again. I registered actions and trying to connect.

Logs 333.211038: 05, onConnectionSuspended (int cause) - is mGoogleApiClient connected? = true 334.211038: 05, onConnectionSuspended (int cause) - is mGoogleApiClient connected? = false

But even after 2 minutes with my phone outdoors with a clear sky, etc., this is not a connection. I have to restart the activity in order to get the connection again. Can someone help me?

+4
source share
1 answer

I ran into the same problem and the Google API connection failed. I manually made a call connect()and lingered on 1000ms, and only after that my connections failed.

@Override
public void onConnectionSuspended(int i) {
  new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
      googleApiClient.connect();
    }
  }, 1000);
}
+2
source

All Articles