我正在使用cordova 3.3.0。在我的应用程序中,当我点击后退按钮时,一旦应用程序启动,应用程序就会崩溃。
我已在主要活动中处理了后退按钮操作,但结果相同。
以下是崩溃。
03-19 14:40:53.254: E/AndroidRuntime(23449): FATAL EXCEPTION: main
03-19 14:40:53.254: E/AndroidRuntime(23449): Process: com.example.example, PID: 23449
03-19 14:40:53.254: E/AndroidRuntime(23449): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@420b9d30 is not valid; is your activity running?
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.view.ViewRootImpl.setView(ViewRootImpl.java:536)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.app.Dialog.show(Dialog.java:286) 03-19 14:40:53.254: E/AndroidRuntime(23449): at org.apache.cordova.DroidGap$5.run(DroidGap.java:1038)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.os.Handler.handleCallback(Handler.java:733)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.os.Handler.dispatchMessage(Handler.java:95)
03-19 14:40:53.254: E/AndroidRuntime(23449): at android.os.Looper.loop(Looper.java:136) 03-19 14:40:53.254: E/AndroidRuntime(23449): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-19 14:40:53.254: E/AndroidRuntime(23449): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 14:40:53.254: E/AndroidRuntime(23449): at java.lang.reflect.Method.invoke(Method.java:515)
03-19 14:40:53.254: E/AndroidRuntime(23449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-19 14:40:53.254: E/AndroidRuntime(23449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-19 14:40:53.254: E/AndroidRuntime(23449): at dalvik.system.NativeStart.main(Native Method)
提前致谢
答案 0 :(得分:0)
公共类MainActivity扩展了DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
new CordovaWebClient(this, appView);
super.loadUrl("file:///android_asset/www/index.html");
}
@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 void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
Log.e("Error", "Received SSL error"+ error.toString());
handler.proceed();
}
@Override
public void init() {
Log.e(TAG, "init()");
CordovaWebView webView = new CordovaWebView(MainActivity.this);
CordovaWebViewClient webViewClient;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
{
webViewClient = new CordovaWebViewClient(this, webView);
}
else
{
webViewClient = new IceCreamCordovaWebViewClient(this, webView);
}
this.init(webView, webViewClient, new MyCordovaChromeClient(this, webView));
}
private class MyCordovaChromeClient extends CordovaChromeClient{
private CordovaInterface cordova;
public MyCordovaChromeClient(CordovaInterface ctx, CordovaWebView app) {
super(ctx, app);
this.cordova = ctx;
}