I have seen this question on OnConnecctionSuspended() call back. StackOverflow Question
I have an activity where I'm trying to track the KMs traveled from origin to destination when a user clicks a start button (origin) and then clicks stop button (Destination). The issues is that it works perfectly for some 1.5-2 KMs after which the connection is suspended with cause 1, for which the google doc says 'CAUSE_SERVICE_DISCONNECTED' - A suspension cause informing that the service has been killed. As per the answer provided by hounshell it will automatically try connecting and we dont have to call googleApiClient.connect() method again. I have logged the actions and it is trying to connect.
Logs 333,211038:05,onConnectionSuspended(int cause)- mGoogleApiClient is Connecting? = true 334,211038:05,onConnectionSuspended(int cause)- mGoogleApiClient is Connected? = false
But even after 2 mins with my phone out in the open with clear skies etc, its not connecting. I have to restart the activity to get the connection again. Can someone help me please???
I ran into the same problem and the Google API connection would not succeed. I manually made the connect()
call and delayed by 1000ms
, and only then did my connections succeed.
@Override
public void onConnectionSuspended(int i) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
googleApiClient.connect();
}
}, 1000);
}