Hi guys, in my code i use the method to close the application when the back button is pressed, in my main(): this->setKeypadEnabled(true);
and create this function:
void MainMenu::
onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event)
{
if (keyCode == EventKeyboard::KeyCode::KEY_BACK)
{
Director::getInstance()->end();
}
}
in theory this works, because i search and this is the method to close my application, but when i press the button, the application close but it show me the message: “unafourtly myAppName application stopped”.
In my Eclipse log, appear this message:
04-14 05:25:45.483: E/dalvikvm(20611): Loading ARM symbol: Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent
04-14 05:25:45.483: E/dalvikvm(20611): Loading ARM symbol: Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent__IZ
04-14 05:25:45.483: W/dalvikvm(20611): No implementation found for native Lorg/cocos2dx/lib/Cocos2dxRenderer;.nativeKeyEvent:(IZ)Z
04-14 05:25:45.499: W/dalvikvm(20611): threadid=12: thread exiting with uncaught exception (group=0xa61b0908)
04-14 05:25:45.499: E/AndroidRuntime(20611): FATAL EXCEPTION: GLThread 175
04-14 05:25:45.499: E/AndroidRuntime(20611): java.lang.UnsatisfiedLinkError: Native method not found: org.cocos2dx.lib.Cocos2dxRenderer.nativeKeyEvent:(IZ)Z
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxRenderer.nativeKeyEvent(Native Method)
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxRenderer.handleKeyDown(Cocos2dxRenderer.java:140)
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$11.run(Cocos2dxGLSurfaceView.java:327)
04-14 05:25:45.499: E/AndroidRuntime(20611): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
04-14 05:25:45.499: E/AndroidRuntime(20611): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
IIRC setKeypadEnabled is deprecated. In fact Layer itself should be deprecated.
Do this instead -
auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event *event) {
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE) {
Director::getInstance()->end();
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
1 Like
Hi i_d_k thanks for your help, but it didnt work
the log in the console send me again this errors when i press the back button
04-14 05:25:45.483: E/dalvikvm(20611): Loading ARM symbol: Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent
04-14 05:25:45.483: E/dalvikvm(20611): Loading ARM symbol: Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent__IZ
04-14 05:25:45.483: W/dalvikvm(20611): No implementation found for native Lorg/cocos2dx/lib/Cocos2dxRenderer;.nativeKeyEvent:(IZ)Z
04-14 05:25:45.499: W/dalvikvm(20611): threadid=12: thread exiting with uncaught exception (group=0xa61b0908)
04-14 05:25:45.499: E/AndroidRuntime(20611): FATAL EXCEPTION: GLThread 175
04-14 05:25:45.499: E/AndroidRuntime(20611): java.lang.UnsatisfiedLinkError: Native method not found: org.cocos2dx.lib.Cocos2dxRenderer.nativeKeyEvent:(IZ)Z
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxRenderer.nativeKeyEvent(Native Method)
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxRenderer.handleKeyDown(Cocos2dxRenderer.java:140)
04-14 05:25:45.499: E/AndroidRuntime(20611): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$11.run(Cocos2dxGLSurfaceView.java:327)
04-14 05:25:45.499: E/AndroidRuntime(20611): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
04-14 05:25:45.499: E/AndroidRuntime(20611): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
It seems to be working fine for me.
What device are you running on?
I solved the problem updating my cocos version to cocos 3.10. Seems like the problem was in my Android project classes. Anyways thanks for your help, your method works perfectly 
1 Like