Android Question Disable Context Menu

rogersantosferreira

Member
Licensed User
Longtime User
Hi everyone...

How can I disable the context menu on Android's B4A app?
I can't find anything like that on forum. My app is crashing ("app failed unexpected") when I press the menu button on an old device and so when I do a longTouch on context button on newer devices.

Thanks in advance.
 

rogersantosferreira

Member
Licensed User
Longtime User
When I try to access a context menu (on old and new devices) I get this error by log console:

main$HandleKeyDelayedrunDirectly (B4A line: 66)
End Sub
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at speech.app.main$HandleKeyDelayed.runDirectly(main.java:224)
at speech.app.main.onKeyDown(main.java:211)
at android.view.KeyEvent.dispatch(KeyEvent.java:3173)
at android.app.Activity.dispatchKeyEvent(Activity.java:2529)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2181)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4665)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4632)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4197)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4251)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4220)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4331)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4228)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4388)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4197)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4251)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4220)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4228)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4197)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4251)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4220)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4364)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4524)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2215)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1863)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1854)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2192)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)


I just remove this code below and everything is fine now!

'trying to remove the app from memory
Sub Activity_KeyPress (KeyCode As Int)
If KeyCode = KeyCodes.KEYCODE_BACK Then
ExitApplication
End If
End Sub


Why this happens?
Thanks one more time, Erel.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Should the sub Activity_KeyPress return a Boolean value to indicate if it has handled the key press?

A sub that returns no value does in fact, internally, return a String.
So android expects a Boolean but gets a String - hence the class cast exception.
 
Upvote 0

rogersantosferreira

Member
Licensed User
Longtime User
Should the sub Activity_KeyPress return a Boolean value to indicate if it has handled the key press?

A sub that returns no value does in fact, internally, return a String.
So android expects a Boolean but gets a String - hence the class cast exception.

Exactly warwound! You're completely right!
Thanks for the support.
 
Upvote 0
Top