开发者

Native Android Menu in Phonegap. Can't get my code to work

开发者 https://www.devze.com 2023-04-12 07:51 出处:网络
I\'m currently building a mobile application with phonegap. Since I\'m having trouble with consistent HTML5 Storage when restarting the phone/app I want to add a native Android menu for closing the ap

I'm currently building a mobile application with phonegap.

Since I'm having trouble with consistent HTML5 Storage when restarting the phone/app I want to add a native Android menu for closing the app for testing purposes since it is really annoying to force close it via the application manager.

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;
}

}

I get no warnings or errors in Eclipse.

When hitting the menu button nothing really happens. Any suggestions ? Thanks in advance :)

[Edit]: Here is the logfile:

 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 1开发者_运维问答0: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


I dont see why your using a superclass. Try removing the super and place the two option menu functions on top of your oncreate function. Else, i dont see any problems with your code at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号