A
A
Andrey Filatov2015-08-27 15:50:57
Android
Andrey Filatov, 2015-08-27 15:50:57

How to connect Play Game Services on Android correctly, provided that the application has more than one activity?

It was necessary to connect Play Games Services to the Android application (authorization, achievements and leaderboard).
Documentation and examples https://developers.google.com/games/services/andro... describe the connection process within a single activity. More specifically, it is alarming that you need to connect in the onStart () method, and disconnect in the onStop () method. We have several activities in our application and calls to Play Games Services must be made from different activities, for example, the result of the game and achievements are different activities.
In connection with all this, the question arose, how to properly implement the integration? After all, when we switch to another activity in the previous one, onStop () may occur.
By the way, the same topic is present when billing is connected.
I would be grateful for answers)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Filatov, 2015-08-28
@filatoff

I found a great example that answers all my questions on this topic https://github.com/playgameservices/android-basic-... In short, there is a BaseGameUtils library that already implements an abstract activity and a helper for working with the service . With a little refinement with a file (for example, I already have an activity, from which everyone inherits, I had to transfer the logic from the library there), everything turned out to be implemented. The examples also cover the main examples of using this library (login, achievements, etc.)

K
Konstantin Berkov, 2015-08-27
@konstantin_berkow

Of course, I’m not sure, I don’t have experience with these services, but in many similar cases (session tracking, binding to a service), it’s worth connecting in onResume () and disconnecting in onPause (), make some kind of abstract activity that will deal with this, and the rest will inherit from it.

I
illuzor, 2015-08-27
@iLLuzor

After all, you can create a separate class that will manage all this business. Linking to an activity is not required.

R
Rustem Saitkulov, 2015-08-28
@atetc

Activity Lifecycler to use, which will connect any activity to the Play Services API
Or inherit a custom activist in which the subscription / unsubscription occurs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question