Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet

后端 未结 5 654
暖寄归人
暖寄归人 2021-01-18 02:13

I am getting this error message when trying to implement logout for Google Sign-In for Android:

Caused by: java.lang.IllegalStateException: GoogleApiClient i         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 03:00

    I know its quite old post and already answered.

    However, the actual cause of the error is not object creation at single or multiple places but "enableAutoManage" invocation at the time of Building Client object.

    The API doc here suggests that it would automatically do the life cycle management by calling methods on onStart & onStop methods of the activity.

    Therefore, if you want to use the same object across different activities then you should avoid calling "enableAutoManage" and invoke apiObject.connect(preferably in onStart of activity) and apiObject.disconnect() (preferably in onStop of activity).

    This worked for me, therefore sharing.

提交回复
热议问题