I think this may be a Xamarin bug. The repro test project is at https://github.com/lauxjpn/ExitTest02
I might be a bad interaction between Mono and Dalvik/Art/Java, I'll investigate. But, in general, it's better to call Activity.Finish() in the launcher activity to quit the Android app - much safer.
I can confirm this behaviour. Repeating the reproduction steps here:
1. Open the attached project in Visual Studio for Mac
2. Set a break point in the Android project in the `SomeActivity.OnBackPressed` method.
3. Run the application
4. Click the "Disable" button
5. Click on the system back button
6. The app will hang.
All this said, it would be more appropriate to call `Activity.Finish()` than to call `System.Environment.Exit()`
Created attachment 23116 [details]
Sample project duplicating the bug.
Why is `Environment.Exit()` being called in the first place? Normally the Android process should not be exited by user code; Android will kill the process when necessary.
No idea why the user is doing this. It was originally a bug filed with MvvmCross and I punted it here.
I am running into this issue. It is holding up our unit test automation. The have a usecase for calling Environment.Exit(). After unit tests are run and test run is complete, I want to exit the app/process. I have a batch script that looks for running process via package name. As soon as the pid becomes empty, I want to fetch the unit test results file from sdcard to local disk.
So in my app I called System.Enviornment.Exit(1); This causes the app to hang. which leaves the process running forever. Jenkins job never finishes because pid is not empty.
I would really appreciate any workaround or insight on how can I achieve this.
Basically I want my app to terminate after test run is complete and the app knows when tests runs are complete. I want to exit right after that.