4

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???

Community
  • 1
  • 1
Jerokdeep
  • 121
  • 13

1 Answers1

2

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);
}
matt---
  • 2,470
  • 2
  • 20
  • 20
  • Strange but works. We have implemented a complete restart mechanism (app) to get this work. Thanks for this. – Jerokdeep Mar 28 '16 at 05:28
  • i tried this to reconnect but i am unable to connect every time it i'll call onConnectionSuspended() what can i do for that – Ganesh Gudghe Feb 22 '17 at 05:05