[mono-android] How to force an exit gracefully

Brian Long brian at blong.com
Wed Mar 30 11:53:48 EDT 2011


>>I would instead suggest that your main activity launch the login activity using Activity.StartActivityForResult()[0] with a requestCode >= 0. The login activity would then use Activity.SetResult()[1] to specify success/failure and call Activity.Finish()[2] to dismiss the login activity, and your main activity would override Activity.OnActivityResult()[3] to see if the login activity succeeded or failed; if the login activity failed, the main activity can call Activity.Finish() to dismiss itself as well.

>>Now, why shouldn't you call Environment.Exit()/etc.? Because processes aren't cheap -- it requires loading libmonodroid.so, the Mono JIT, loading assemblies, etc. This is why the initial launch of a Mono for Android device is ~3s on hardware, yet Back Button + restart is nigh instantaneous -- the process is being reused. You really don't want to screw with this unless you have a really good reason.

Thanks Jon

And thanks also Matt for the link.

I understand the sensible flow now - all makes sense.

- Brian


More information about the Monodroid mailing list