Hello @Eduardo Gomez !
Based on the information you've provided, the problem seems to be related to the debugging process itself rather than your application logic, especially since it works fine in Release mode.
A common cause for this kind of behavior is "Application Not Responding" (ANR) error, a timeout in the Android operating system, which can be triggered when the debugger is attached. The debugger can sometimes pause threads for inspection, and if a critical thread like the main UI thread is paused for too long (even for a few seconds), Android may terminate the application, assuming it has become unresponsive.
To prevent the debugger from breaking on these specific exceptions and allow your application to handle them gracefully, you can configure the debugger settings in Visual Studio:
- In Visual Studio, go to the Debug > Windows > Exception Settings menu.
- In the Exception Settings window, use the search box to find the following exceptions and uncheck them:
-
Java.Lang.Error -
Java.Lang.Throwable
-
This means that you are telling the debugger not to break when these exceptions are thrown, which can prevent the debugger-induced ANR and allow your app to continue running.
If the issue persists after changing these settings, it would be helpful to get more information from the device logs. You can view these logs using the Device Log tool in Visual Studio while your application is running.
- Connect your physical device.
- Go to Tools > Android > Device Log to open the logcat viewer.
- Start debugging your application (F5).
- When the application crashes, stop debugging and examine the logs in the Device Log window for any errors or warnings that occurred around the time of the crash. Look for messages related to your application's package name.
I hope this helps!