Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 872
GDanger Avatar asked Jun 10 '14 17:06

GDanger


1 Answers

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.

like image 174
free3dom Avatar answered Sep 28 '22 00:09

free3dom