2014-03-19 166 views
2

我正在使用cordova 3.3.0。在我的應用程序中,當我點擊返回按鈕時,一旦應用程序啓動,應用程序就會崩潰。Phonegap Android應用程序崩潰,當點擊返回按鈕

我在主要活動中處理了後退按鈕操作,但結果相同。

以下是崩潰。

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 [email protected] 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

Sid,它的理由是webview多數民衆贊成它。我加載了像\t super.loadUrl(「file:///android_asset/www/index.html」); –

+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; 
    } 
相關問題