[EDIT]
Since it seems that updating to the latest version of Xamarin Android has altered the nature of this problem, I’ve edited this thread appropriately.
The problem I’m now getting consistently is that described in my second post below: whenever I hit the home button while my game is running, then try to restart, the game hangs during the resume process with a continual sequence of GC_OLD_BRIDGE and GC_MINOR log messages in debug build following the GraphicsDevice.ResetClientBounds log entry (release build just hangs).
This can be replicated in the following manner:
In Visual Studio 2010, create a new Windows Phone 7.1 project (to get
the empty Game1 class).
In Xamarin studio, create a new Android application.
From Monogame 3.2, add the Lidgren and Monogame.Android projects to
the solution
Add references to OpenTK, Lidgren and Monogame.Android in the project
created by the solution.
Set minimum Android version for the project created by the solution
to 2.2 in the project options
Add a link to the Game1.cs file created by the VS new project
Update MainActivity.cs as below:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Microsoft.Xna.Framework;
namespace [your app namespace]
{
[Activity (Label = “TSTest2”, MainLauncher = true, Icon = “@drawable/icon”)]
public class MainActivity : AndroidGameActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
FrameLayout Layout = new FrameLayout(this);
Game1.Activity = this;
Game1 game = new Game1();
Layout.AddView(game.Window);
SetContentView (Layout);
game.Run();
}
}
}
Run the application (should get the blue screen)
Hit the Home button
Find and tap on the application’s icon to restart
The application will now hang while trying to resume. This was tested on a Samsung Galaxy S running Gingerbread.
Okay, so I updated everything to the latest versions - unfortunately, this has mde things worse:
Attempting to resume in debug mode now causes the game to hang, with a series of log entries along the lines of the following:
this follows directly after [MonoGame] GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:0 Width:480 Height:800} in the log.
I tried adding a “NoHistory = true” attribute to my activity, but that just resulted in another crash on resume - the “MakeCurrent” call in AndroidGameWindow.Onload throws an error.
I’m using Monogame 3.2 and the latest version of Xamarin Android.
Galaxy S/Android 2.3.3:
Both my game and the test app detailed above lock with GC errors on resume
Nokia X/Android 4.1.2:
Both my game and the test app resume correctly. However, following a resume, my game is throwing an error on exit in SpriteBatch.Setup (gd == null).
Android 15 & 17 Emulator:
My game failed completely to resume, not even getting the GC errors - I’m guessing that this is due to the size of the game and the amount of content it has, plus the emulator being dog-slow. Test app resumes correctly.
Since the Nokia X has less memory than the Galaxy, I’m guessing that this is specific to older Android versions, but just don’t have the hardware to confirm.