The app crashes when the key back button is pressed on a certain screen. Curiosly, it only crashes in real devices like a phone or a tablet, in the emulator works well.
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
If (intNUM_PANTALLA = 1) Then
pantalla_principal
Return True
Else If (intNUM_PANTALLA = 2) Then
pantalla_referencia
Return True 'Here is where the app crashes
Else If (intNUM_PANTALLA = 3) Then
pantalla_principal
Return True
End If
End If
End Sub
I'm searching the reason and the problem is because of a table class view added in 'pantalla_referencia' sub.
B4X:
Sub pantalla_referencia
.
.
.
tbREFERENCIADB.Initialize(Me, "tbREFERENCIADB", 3)
tbREFERENCIADB.AddToActivity(pnlREFERENCIADB, 0, 0, pnlREFERENCIADB.Width, pnlREFERENCIADB.Height - 20%y)
tbREFERENCIADB.SetHeader(Array As String("Referencia", "Máquina", "Puesto trabajo"))
tbREFERENCIADB.SetColumnsWidths(Array As Int(35%x, 20%x, 35%x))
tbREFERENCIADB.FontSize = 16 * TextSizeRatio
.
.
.
end sub
If I delete these lines the keyback function works fine. The log windows doesn´t show any error. In others parts of the app I call this sub and executes fine without problems, only crashes in the 'return true' line from key back. If I make a breakpoint in the 'return true' line I see in the screen device that the table has been created.
I have a similar problem with the back button.
I am using the following code and the result of pushing the back button differ on a 2.3.3 device and a KitKat one.
The earlier device works fine and I can go thru the cycle of hitting the back button and responding "no" many times without it killing the app.
Yet on the KitKat phone it will kill it. That is not always immediate, sometimes allowing 2 or 3 goes at doing it, but it eventually fails. Once it fails, after restarting the app it results in an immediate fail when trying the 'no' option again.
My app has an activity and a service which handles sms messages, but the same apk on each phone behaves differently.
Any clues? I am using activity.finish to allow the service to keep running.
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
Log("keypress")
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("Are you sure to exit?", "", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
'Log("Yes")
Return False
'ExitApplication '...or whatever other previous killing actions.
Activity.Finish
Else
'Log("No")
Return True
End If
End If
End Sub
Edit:
I have created a new app with no more than a label and a button and get the exact same results. KitKat fails when responding "no" to the back button.
It will not happen with the latest version of B4A. I highly recommend you to update to a newer version. If you like, contact support@basic4ppc.com and we will send you a discount offer.