GoogleApiClient is not connected yet exception

前端 未结 2 802
一个人的身影
一个人的身影 2021-01-13 08:32

The application i\'m working on, works properly sometimes but some other times it gives me this error

FATAL EXCEPTION: java.lang.RuntimeException: Una

相关标签:
2条回答
  • 2021-01-13 08:45

    You should not call loc.createLocationRequest(); immediate after you call loc.buildGoogleApiClient(); Instead you call loc.createLocationRequest() in onConected() of ApiCLient. loc.createLocationRequest() requires the GoogleApiClient to be connected by the time it is called.

    For that matter, you should call any API that needs APiCLient connected in onConnected(). This way you avoid ApiClient connect exceptions while you use them.

    0 讨论(0)
  • 2021-01-13 08:56

    This is coming late but for whoever it might be useful for:

    1. Move loc.buildGoogleApiClient(); to the onCreate method.
    2. Move loc.createLocationRequest(); to the onConnected method.
    0 讨论(0)
提交回复
热议问题