在我的应用中,一些 Google API 是可选的。 (在本例中为游戏 API。)
在我的设置 Activity 中,用户可以选择不登录 Google 游戏。我调用那里
Games.signOut(mGoogleApiClient);
googleApiClient.disconnect();
googleApiClient = createGoogleApiClientWithoutGames();
googleApiClient.connect();
createGoogleApiClientWithoutGames
方法创建一个不使用游戏 API 和相应范围的新 GoogleApiClient。
这是从客户端删除 api 和范围的正确方法吗?
如何确保其他 Activity (尚未销毁)的 googleApiClient 不使用游戏 API?当前,当从设置 Activity 返回时,客户端正在使用当前客户端配置(使用游戏)在
onStart()
中进行连接。发送本地广播消息并重新创建客户端?
最佳答案
我正在使用一个状态变量来检查 onStart()
MainActivity 中的当前客户端是否使用了正确的 api。如果不是,我会在连接之前重新创建它。
完整的源代码可在 https://github.com/friedger/google-api-client-example 获得。
关于android - 如何从 Android 中的 GoogleApiClient 中删除 api 和范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35085725/