How do you provide a GoogleApiClient dependency with Dagger2?

ⅰ亾dé卋堺 提交于 2019-12-05 05:02:59

You can use the injection to create the client

 @Provides
    @Singleton
    GoogleApiClient providesGoogleApiClient(Context context) {
            return new GoogleApiClient.Builder(context)
                    .addApi(Places.GEO_DATA_API)
                    .addApi(LocationServices.API)
                    .build();
        }

And then manage the call backs on your activity

@Inject GoogleApiClient mGoogleApiClient;



if (mGoogleApiClient != null) {  mGoogleApiClient.registerConnectionCallbacks(this);            mGoogleApiClient.registerConnectionFailedListener`(this);
}

I hope this might help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!