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

In my gaming application, I would like the user to log into the Google Play service during the initial activity, so I had a subclass of BaseGameActivity . Then, for the game, a separate action begins, at the end of which I want to update the leaderboard using Google Play Services, for which I need to call BaseGameActivity.getApiClient() .

How do I use Google Play services from another action, except that subclasses BaseGameActivity ?

Two options that I was thinking about are: pass a link to the initial activity or use a handler and send a message to the initial operation. But I don’t know which method is better to use (or if the third method is better), and it looks like this might be a fairly common situation.

+6
source share
1 answer

If you want to use a GameHelper with multiple actions, it's best to implement it without using BaseGameActivity , and then pass the GameHelper instance between the actions (or save 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 you place the required GameHelper calls (especially onActivityResult ) in all of your activities that use it. As for entry / exit, you will need to determine for yourself in what actions (s) to place them, depending on the flow of your application.

+4
source

Source: https://habr.com/ru/post/970639/


All Articles