3

I want to use BaseGameActivity from the games examples:

https://github.com/playgameservices/android-samples/blob/master/BaseGameUtils/src/com/google/example/games/basegameutils/BaseGameActivity.java

but my game activity has to extend from another framework's activity class. Is there an implementation of BaseGameActivity factored out into a separate class so I don't have to have my activity inherit from it?

Thanks

user291701
  • 38,411
  • 72
  • 187
  • 285
  • 1
    the link is broken. [here](https://github.com/playgameservices/android-samples/blob/master/libraries/BaseGameUtils/src/com/google/example/games/basegameutils/BaseGameActivity.java) it is – tjPark Jul 28 '13 at 14:44

2 Answers2

16

BaseGameActivity is a pretty simple wrapper around GameHelper, which is the object that really does all the work. If you can't derive from BaseGameActivity, simply use GameHelper directly. The implementation of the BaseGameActivity class can serve as an example of how to hook up the GameHelper methods to your Activity's lifecycle.

In summary:

  • in your Activity's onCreate, create the GameHelper object.
  • from your Activity's onStart, call GameHelper's onStart
  • from your Activity's onStop, call GameHelper's onStop.
  • from your Activity's onActivityResult, call GameHelper's onActivityResult.
  • implement the GameHelperListener interface methods
Bruno Oliveira
  • 5,056
  • 18
  • 24
2

There's no requirement to use exactly that BaseGameActivity. Create your own BaseGameActivity based on that source code but instead of

public abstract class BaseGameActivity extends FragmentActivity implements
    GameHelper.GameHelperListener

put

public abstract class BaseGameActivity extends YourFrameworksActivity implements
    GameHelper.GameHelperListener
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443