I have a problem with try/catch in a sub. The problem is that the code for some mobile phones (Samsung, I'm looking at you!) crash within the try block. I was under the impression that if something crashed in a try-block, all would be good and we'd instead run the code in the catch-block. But here I'm seeing that the app actually crashes.
Have I misunderstood something about try/catch? Or is it simply that I'm doing things "outside" B4X, so to speak, by using JavaObject and running methods there, and the try/catch can't actually catch those crashes?
This the sub:
Have I misunderstood something about try/catch? Or is it simply that I'm doing things "outside" B4X, so to speak, by using JavaObject and running methods there, and the try/catch can't actually catch those crashes?
This the sub:
B4X:
Private Sub getLabelLocationForAllowAllTime As String
Try
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Dim res As JavaObject = PackageManager.RunMethod("getResourcesForApplication", Array("com.google.android.permissioncontroller")) ' This line will crash on some phones
Dim resId As Int = res.RunMethod("getIdentifier", Array("app_permission_button_allow_always", "string", "com.android.permissioncontroller"))
Dim result As String = res.RunMethod("getString", Array(resId))
Return result
Catch
Return "fallback string"
End Try
End Sub