I`ve just noticed a problem with the B4XFloatTextField in my app when I press the Backspace ket to delete its contents; when I`ve deleted everything if I press Backspace again the app crashes. Is this a normal phenomenon on B4XFloatTextField?
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at RAID.FirstAid.main$HandleKeyDelayed.runDirectly(main.java:232)
at RAID.FirstAid.main.onKeyDown(main.java:219)
at android.view.KeyEvent.dispatch(KeyEvent.java:3350)
at android.app.Activity.dispatchKeyEvent(Activity.java:3451)
at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.java:108)
at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:84)
at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:126)
at androidx.appcompat.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:535)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:2533)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:564)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:6035)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5890)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5343)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5396)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5362)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5521)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5370)
Sub Activity_KeyPress (KeyCode As Int)
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("You hit the BACK button, do you want to close the app?", "", "Yes", "", "No",LoadBitmap (File.DirAssets, "question.png")) = DialogResponse.POSITIVE Then
ExitApplication
Else
Return
End If
End If
End Sub
You never should use MsgBox. Use the Async methods instead.
Example:
B4X:
Msgbox2Async("Delete?", "Title", "Yes", "Cancel", "No", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
'...
End If
untested code
B4X:
Sub Activity_KeyPress (KeyCode As Int)
If KeyCode = KeyCodes.KEYCODE_BACK Then
Msgbox2Async("You hit the BACK button, do you want to close the app?", "", "Yes", "", "No", LoadBitmap (File.DirAssets, "question.png"), False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
ExitApplication
End If
Else
Return
End If
End Sub
Maybe you need to create a resumeable sub to show the msgbox.
1. The event signature is wrong. The return type is missing. This is the reason for the crash.
2. You should never use Msgbox or Msgbox2. Only the async version.
3. You shouldn't use ExitApplication.