[SOLVED] OnResume Crashes but only in signed/aligned version

So, ive been plagued by OnResume crashes since I started using MonoGame and today I tried to put an end to it, I’ve updated to the latest MonoGame (3.4) which seems to have fixed most of the previous issues but I’m still having problems.

When I run my app in debug/release mode it works fine and resume brings the app back without problems but once I’ve signed and zip aligned my apk so its ready for release it will crash every single time when its resumed.

Kinda hard to debug since I can only reproduce it when its signed and ready for release, is anyone else able to reproduce this or have any idea what the cause might be?

I should also point out I’m testing on a Samsung Galaxy Tab 3 and a Samsung Galaxy S3 Mini.

So I crashed my live app on GooglePlay and reported the crash… heres the stack trace google gives me:

java.lang.IllegalStateException
in android.view.ViewGroup.addViewInner

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2412)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3783)
at android.view.ViewGroup.addView(ViewGroup.java:3632)
at android.view.ViewGroup.addView(ViewGroup.java:3577)
at android.view.ViewGroup.addView(ViewGroup.java:3553)
at md568c8de65a12d13eba5b41378666229d2.MainActivity.n_onCreate(Native Method)
at md568c8de65a12d13eba5b41378666229d2.MainActivity.onCreate(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:5458)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)

Turns out I was missing: ‘LaunchMode = LaunchMode.SingleTask, AlwaysRetainTaskState = true’ in my Activity… adding that and upgrading to MonoGame 3.4 seems (fingers crossed) to have resolved all resume issues.

Very weird how I could only make it happen once the apk was signed/aligned though.

Thanks for posting how you fixed this, will do the same :slight_smile:

So is this something we should change in the default MonoGame template project for Android?

LaunchMode.SingleInstance is the current one in the template, which breaks intent results. All intent results are cancelled with that launch mode, breaking in app purchases for example.

The game works fine for us with default LaunchMode and AlwaysRetainTaskState (not sure about the default values, we just didn’t define them for the activity). I’m fine with changing the template, but LaunchMode.SingleTask also breaks StartActivityForResult.

See:

I would say yes since SingleTask is less likely to cause problems for most scenarios… a lot of people will be adding IAPs to their game for example.

If I recall correctly I had removed LaunchMode.SingleInstance and left it undefined because it was causing problems with OnActivityResult… I had also removed ‘retaintaskstate = true’ though, which may have been what was causing the crash on resume problems for me.

Then I guess it would be best to remove the LaunchMode from the template.