4

I am a C# developer working on conversions to Mono Android. These conversions work perfectly, except for when the phone times out or blacks out and the user touches the screen again.... The game is lost.

What is the simplest way of dealing with this? I have heard it referred to as the life cycle, and found many brief descriptions of this cycle without explanations of how to implement it with real examples, and especially, how to implement it with XNA conversions.

My first solution would be to have a 'Pause' method in the XNA game, and run that method for the 'onPause' of the Android. However there may be simpler ways of dealing with this, as I have heard there are simple Mono Android settings to pick that will deal with time outs and phone calls automatically.

What I ask is.. How do I make my XnA conversion continue to run through a phone call, screen timeouts, etc?

poupou
  • 43,413
  • 6
  • 77
  • 174

1 Answers1

1

Might I ask if you are using MonoGame or simply the AndroidGameView that comes with Mono for Android?

If you are using AndroidGameView, I suggest you follow the convention of reloading the textures manually in OnLoad() as per the textured cube sample.

When using MonoGame, if you load textures via ContentManager.Load<Texture2D>(), reloading is handled for you. Textures loaded using Texture2D.FromStream must be manually reloaded in the GraphicsDevice.DeviceReset event.

As Andrew Russell pointed out, ExEn has the advantage that it doesn't need to reload the textures on every resume. However, it is still necessary (or good practice at least) to support reloading graphics resources on Android. On many devices your game will not be able to gracefully recover from switching away and back without it. ExEn currently has no support for reloading textures.

Xamarin are currently working on fixing a bug in AndroidGameView that will allow it to correctly resume where the device supports it. Once released, this should flow through to MonoGame.

Aside from reloading textures and other graphics resources, handling of the life cycle should be fairly trivial. MonoGame has not yet implemented the complete Windows Phone life cycle (ie the tombstone and rehydrate), but in my experience, it's not necessary. You can use the Game.Activated and Game.Deactivated events for things like showing the pause screen when resuming in-game.

Aranda
  • 855
  • 8
  • 17