在使用android的手机间隙项目中,当我按下按钮时,它会停止(关闭)我的应用程序
使用此logcat结果
08-22 05:35:12.106: W/dalvikvm(1154): threadid=1: thread exiting with uncaught exception (group=0xa6280288)
08-22 05:35:12.106: E/AndroidRuntime(1154): FATAL EXCEPTION: main
08-22 05:35:12.106: E/AndroidRuntime(1154): java.lang.NullPointerException
08-22 05:35:12.106: E/AndroidRuntime(1154): at org.apache.cordova.CordovaActivity.onKeyDown(CordovaActivity.java:1084)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.view.KeyEvent.dispatch(KeyEvent.java:2609)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.app.Activity.dispatchKeyEvent(Activity.java:2361)
08-22 05:35:12.106: E/AndroidRuntime(1154): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3545)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2795)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.os.Looper.loop(Looper.java:137)
08-22 05:35:12.106: E/AndroidRuntime(1154): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-22 05:35:12.106: E/AndroidRuntime(1154): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 05:35:12.106: E/AndroidRuntime(1154): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 05:35:12.106: E/AndroidRuntime(1154): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-22 05:35:12.106: E/AndroidRuntime(1154): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-22 05:35:12.106: E/AndroidRuntime(1154): at dalvik.system.NativeStart.main(Native Method)
这是我的活动课
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// super.loadUrl("file:///android_asset/www/firstfile.html");
wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setPluginState(PluginState.ON);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
// wv.loadUrl("file:///android_asset/www/firstfile.html");
wv.loadUrl("file:///android_asset/www/test.html");
MyWebViewClient wvc = new MyWebViewClient();
wv.setWebViewClient(wvc);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class MyWebViewClient extends WebViewClient {
ProgressDialog prDialog;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
prDialog = ProgressDialog.show(MainActivity.this, null,
"loading, please wait...");
prDialog.setCancelable(true);
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
prDialog.dismiss();
super.onPageFinished(view, url);
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
}
我添加了
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
在我的清单文件中
有人对此有所了解吗?
答案 0 :(得分:1)
您需要处理/覆盖后退按钮事件的默认行为。查看here后退按钮事件处理
答案 1 :(得分:1)
在主活动中添加以下行,这些行来自DroidGap
@Override
public void onBackPressed() {
}