问题描述
在我的游戏应用程序,我想用户登录到谷歌的出发活动中发挥服务,所以我有它的子类 BaseGameActivity
。然后一个单独的活动开始进行游戏,在其中我想更新使用谷歌播放服务,这需要调用 BaseGameActivity.getApiClient()
A排行榜末尾。
In my game app I would like the user to sign in to Google Play Services during the starting activity so I had it subclass BaseGameActivity
. Then a separate activity is started for the game, at the end of which I want to update a leaderboard using Google Play Services, which requires calling BaseGameActivity.getApiClient()
.
我应该如何使用谷歌Play业务从不同的活动不是一个子类 BaseGameActivity
?
How should I use Google Play services from a different activity than the one that subclasses BaseGameActivity
?
两个选择,我想到的是:通过一个参考启动活动,或使用一个处理程序,并发送消息到开始活动。但我不知道这会的方法是更好地使用(或者如果第三种方式是更好的),它看起来这可能是一个相当普遍的情况。
Two options I thought of were: pass a reference to the starting activity, or use a handler and send a message to the starting activity. But I don't know which would method would be better to use (or if a third way is better) and it seems like this might be a fairly common situation.
推荐答案
如果你想使用 GameHelper
多活动,最好是实现它,而无需使用 BaseGameActivity
,然后通过活动之间的 GameHelper
实例(或保持静态实例的地方)。
If you want to use GameHelper
with multiple activities it is best to implement it without using BaseGameActivity
and then pass your GameHelper
instance between activities (or keep a static instance somewhere).
您可以找到使用说明 GameHelper
直接的(看到使用GameHelper没有BaseGameActivity 标题)。
You can find instructions for using GameHelper
directly on this page (see the Using GameHelper without BaseGameActivity heading).
只要确保您将需要 GameHelper
电话(尤其是 onActivityResult
)的所有活动,使中使用它。至于登录/注销,你将需要确定哪些活动(收费)为自己的地方,这取决于你的应用程序的流量。
Just make sure that you place the required GameHelper
calls (especially onActivityResult
) in all of your activities that make use of it. As for sign-on/sign-out you will need to determine for yourself in which activity(s) to place those, depending on the flow of your app.
这篇关于如何在多个活动中使用BaseGameActivity.getApiClient()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!