“GoogleApiClient is not connected yet” exception in Cast application

前端 未结 4 647
暖寄归人
暖寄归人 2020-12-03 15:13

I\'m developing an Android application that casts content to Chromecast. Sometimes in my com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks i

4条回答
  •  星月不相逢
    2020-12-03 15:50

    Google APIs for Android > GoogleApiClient

    You should instantiate a client object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.

    The implementation of the GoogleApiClient appears designed for only a single instance. It's best to instantiate it only once in onCreate, then perform connections and disconnections using the single instance.

    I would guess that only one GoogleApiClient can be actually be connected, but multiple instances are receiving the onConnected callback.

    In your case it's probably fine to not call connect in onStart, but only in onRouteAdded.

    I think this issue is very similar to Fatal Exception: java.lang.IllegalStateException GoogleApiClient is not connected yet

提交回复
热议问题