Phonegap中的原生Android菜单。无法让我的代码工作

时间:2011-10-11 06:34:05

标签: android menu cordova native

我目前正在构建一个带有phonegap的移动应用程序 由于我在重新启动手机/重新启动应用程序时遇到了一致的HTML5存储问题,我想添加原生Android菜单以关闭应用程序以进行测试,因为通过应用程序管理器强行关闭它真的很烦人。

public class GridTestActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    super.loadUrl("file:///android_asset/www/TestPage.html");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = super.getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    Toast.makeText(this, "Menu item pressed", Toast.LENGTH_SHORT).show();
    return true;
}

}

Eclipse中没有警告或错误。

按下菜单按钮时,没有任何事情发生。有什么建议 ? 在此先感谢:)

[编辑]:这是日志文件:

 10-11 10:35:56.611: INFO/dalvikvm(1020): Debugger is active
 10-11 10:35:56.673: INFO/System.out(1020): Debugger has connected
 10-11 10:35:56.673: INFO/System.out(1020): waiting for debugger to settle...
 10-11 10:35:56.872: INFO/System.out(1020): waiting for debugger to settle...
 (...) 
 10-11 10:35:59.146: INFO/System.out(1020): debugger has settled (1433)
 10-11 10:35:59.962: INFO/PhoneGapLog(1020): phonegap.xml missing. Ignoring...
 10-11 10:35:59.962: INFO/System.out(1020): loadUrl(file:///android_asset/www/TestSeite.html)
 10-11 10:35:59.962: INFO/System.out(1020): url=file:///android_asset/www/TestSeite.html baseUrl=file:///android_asset/www/
 10-11 10:36:00.912: DEBUG/SoftKeyboardDetect(1020): We are in our onMeasure method
 10-11 10:36:00.942: DEBUG/SoftKeyboardDetect(1020): Old Height = 0
 10-11 10:36:00.942: DEBUG/SoftKeyboardDetect(1020): Height = 762
 10-11 10:36:00.952: DEBUG/SoftKeyboardDetect(1020): Old Width = 0
 10-11 10:36:00.952: DEBUG/SoftKeyboardDetect(1020): Width = 480
 10-11 10:36:00.962: DEBUG/SoftKeyboardDetect(1020): Ignore this event
 10-11 10:36:01.212: DEBUG/SoftKeyboardDetect(1020): We are in our onMeasure method
 10-11 10:36:01.212: DEBUG/SoftKeyboardDetect(1020): Old Height = 762
 10-11 10:36:01.223: DEBUG/SoftKeyboardDetect(1020): Height = 762
 10-11 10:36:01.223: DEBUG/SoftKeyboardDetect(1020): Old Width = 480
 10-11 10:36:01.223: DEBUG/SoftKeyboardDetect(1020): Width = 480
 10-11 10:36:01.223: DEBUG/SoftKeyboardDetect(1020): Ignore this event
 10-11 10:36:01.311: INFO/ActivityManager(60): Displayed activity com.krones.grid/.GridTestActivity: 4990 ms (total 4990 ms)
 10-11 10:36:02.342: DEBUG/dalvikvm(1020): GC_FOR_MALLOC freed 2460 objects / 226008 bytes in 138ms
 10-11 10:36:03.481: DEBUG/dalvikvm(1020): GC_FOR_MALLOC freed 2046 objects / 253216 bytes in 125ms
 10-11 10:36:06.302: INFO/Database(1020): sqlite returned: error code = 14, msg = cannot open file at source line 25467
 10-11 10:36:07.441: INFO/System.out(1020): WARNING: Back Button Default Behaviour will be overridden.  The backbutton event will be fired!
 10-11 10:36:07.592: WARN/KeyCharacterMap(1020): No keyboard for id 0
 10-11 10:36:07.592: WARN/KeyCharacterMap(1020): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
 10-11 10:36:08.151: DEBUG/dalvikvm(115): GC_EXPLICIT freed 651 objects / 36856 bytes in 1808ms
 10-11 10:36:12.262: DEBUG/dalvikvm(225): GC_EXPLICIT freed 163 objects / 11776 bytes in 115ms
 10-11 10:36:17.261: DEBUG/dalvikvm(260): GC_EXPLICIT freed 47 objects / 2224 bytes in 117ms
 10-11 10:36:20.351: DEBUG/dalvikvm(1020): GC_FOR_MALLOC freed 3631 objects / 614336 bytes in 64ms

1 个答案:

答案 0 :(得分:0)

我不明白为什么你要使用超类。尝试删除super并将两个选项菜单功能放在oncreate功能之上。否则,我根本没有看到您的代码有任何问题。