How to use BaseGameActivity.getApiClient() in multiple activities?

守給你的承諾、 提交于 2019-12-07 03:01:31

问题


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().

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.


回答1:


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).

You can find instructions for using GameHelper directly on this page (see the Using GameHelper without BaseGameActivity heading).

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.



来源:https://stackoverflow.com/questions/24147835/how-to-use-basegameactivity-getapiclient-in-multiple-activities

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