Rob85 Rob85 -4 years ago 102
Android Question

passing the GoogleApiClient obj from one activity to another

I want to be able to update my score for my leaderboard in a different activity other than the one that creates the GoogleApiClient obj ( the main activity ).

What is the best way to do this?

Is making the obj parcelable the correct way? if so how can you do it if the class is part of a library.

Can you make the obj static? is it safe?

Any advice on how to achieve this would be great.

Answer Source

Ok I thought i would answer my own Question as i have found a method that currently suits me. Alot of this has come from another answered question found here!

This method uses the basegameutil so going from Lee's answer from the link i can just have both my activities extend the BaseGameActivity and add the required methods.

I then create a new instance of the GoogleApiClient in my second activity and then get the api client like this:

mGoogleApiClient = getApiClient();

i can now pass this around my second activity and call the methods as i wish.

As Lee States in his answer, you can have multiple instances of the google api client and still wont be asked to sign in for each of them as it knows you are already signed in.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download