谷歌播放服务API code的活动之外? [英] Google Play Services API code outside of an activity?

查看:225
本文介绍了谷歌播放服务API code的活动之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实施谷歌播放服务API到一个应用程序。所有的文档和教程都在code被称为从活动。

When implementing the Google Play Services Api into an app. All of the docs and tutorials have all the code being called from the activity.

我想打破它分成更小的类,我称之为活动中。

I would like to break it out into smaller classes that I call inside the activity.

这是不好的做法?如果没有,我怎样才能使它在非活性类工作?

Is this bad practice? If not, how can I make it work in a non-Activity class?

推荐答案

正确的方法为您的code参加活动的生命周期不硬编码的方法调用是使用片段。

The correct way for your code to participate in the activity lifecycle without hardcoding method calls is to use Fragments.

在GoogleApiClient我们确实有,使谷歌Play业务code来完成大部分的管理为您GoogleApiClient.Builder的enableAutoManage()方法。这可以,如果您的应用程序支持使用GoogleApiClient在某一时间一个谷歌帐户中使用。我们计划很快发布一个示例,显示了此功能。

In GoogleApiClient we do have the enableAutoManage() method on the GoogleApiClient.Builder that enables Google Play services code to do most of the management for you. This can be used if your app supports a single Google Account using GoogleApiClient at a single time. We plan to publish a sample very soon showing this functionality.

您应该知道有,我们会在提示用户的应用程序的OAuth的同意,两次,如果他们拒绝它的第一次automanage功能修复不久的错误。如果现在执行这种修复将是免费的,当你摄取较新的谷歌游戏服务客户端库。

You should know there is a bug that we'll fix shortly in automanage functionality that prompts app users for OAuth consent twice if they reject it the first time. If you implement this now the fix will be free when you pickup the newer Google Play services client library.

<一个href="https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html#enableAutoManage(android.support.v4.app.FragmentActivity" rel="nofollow">https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html#enableAutoManage(android.support.v4.app.FragmentActivity, INT,com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)

https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html#enableAutoManage(android.support.v4.app.FragmentActivity, int, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)

这篇关于谷歌播放服务API code的活动之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆