Google Api Client sometime NULL in onConnected

前端 未结 6 491
小蘑菇
小蘑菇 2021-01-03 23:51

I implement GoogleApiClient as bellow:

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, 0 /* client         


        
6条回答
  •  余生分开走
    2021-01-04 00:31

    build() calls onConnected immediately if you are already connected. Therefore, your variable might be null.

    Better use

    mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, 0 /* clientId */, this)
                .addApi(LocationServices.API)
                .addApi(Places.GEO_DATA_API)
                .addConnectionCallbacks(this);
    mGoogleApiClient.build();
    

提交回复
热议问题