Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass game center data between activities?

Tags:

android

Well, I'm implementing the new game center in android and there is a concept that i don't understand.

I have a class which extends BaseGameActivity (https://developers.google.com/games/services/android/init), so it's the one who manages achievements, leaderboards, Google + sign in, etc. I need another class to be able to access game center data from that activity (unlock achievements, leaderboards, etc), but this class is not called from the extending BaseGameActivity class.

How can they communicate?

The structure is like this (meaning "->" that it starts other activity)

A (extends BaseGameActivity) -> B -> C (needs game center communication with A)

I have read the google's example (TypeANumber) but it uses a Listener to communicate, that's easy when the class you need to communicate with is the one which you are starting, but it's not as easy with my structure.

Any ideas?

Thanks

like image 510
jl1990 Avatar asked May 18 '13 11:05

jl1990


People also ask

How do I transfer my Game Center data?

Navigate the path "Menu" > "Data Linking & Back Up" > "Game Center Account Linking" and log in to your Game Center account. 2. Complete data linking using your Game Center account. 3.

How do I sync game progress between Apple devices?

You can use iCloud and Game Center to keep your progress, high scores, and game saves up-to-date across your devices. If you're signed in to the same iCloud and Game Center accounts and download Apple Arcade games from the App Store on all of your devices, you can access your game saves and progress on all of them.

How do I know what games are linked to Game Center?

The only way to find out is to login with every known account. Gamecenter accounts are easily changeable and doing so doesn't affect the rest of your device because your Apple-ID/iCloud login is seperated from your Gamecenter account.

Is Game Center tied to Apple ID?

When you sign in with your Apple ID, you will be signed in to Game Center automatically. Game Center allows you to engage in game-related activities such as participation in leaderboards; multiplayer games; finding, viewing, and challenging friends; and tracking achievements.


1 Answers

What I think is you have 3 choices:

  1. Create a GamesClient for each Activity that needs it, but you have to call connect() for each activity, and it takes time. After the first connection, the other ones are much faster (a few hundred milliseconds)
  2. Create your own Application class and use it as a context for the GamesClient.Builder, and store your GamesClient object in your Application class. I've tested it, and it works. Now, I know it's discouraged to do that (because it breaks the Android philosophy) but it seems a lot of people prefer to create their own application class and store data into it instead of bundling data and passing them from one activity to another. Its main advantage is that you don't have to modify a lot of thing to make it work in your case (and in mine).
  3. Use Fragment classes instead of Activity classes and use a main Activity which owns the GamesClient object (in that case, your class C would be able to communicate with class A). Like in the example you're mentioning, there's only one Activity which inherits from Google example's BaseGameActivity (which contains the GamesClient instance), and the rest is just Fragment classes (each Fragment being a screen).
like image 50
groug Avatar answered Sep 20 '22 18:09

groug