简体   繁体   English

在android phonegap应用中单击“后退”按钮时强制关闭

[英]force close when clicking the back button in android phonegap app

I have created android phonegap app using html,css,javascript and jquery.When i hit the back button my app gets force closed.My error in the logcat is below: 我已经使用html,css,javascript和jquery创建了android phonegap应用程序。当我按下后退按钮时,我的应用程序被强制关闭。我在logcat中的错误如下:

ERROR/AndroidRuntime(23383): FATAL EXCEPTION: main
    ERROR/AndroidRuntime(23383): android.view.WindowManager
    $BadTokenException: Unable to add window -- token
    android.os.BinderProxy@48c59828 is not valid; is your activity
    running?
    at android.view.ViewRoot.setView(ViewRoot.java:505)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:207)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:121)
    at android.view.Window$LocalWindowManager.addView(Window.java:424)
    at android.app.Dialog.show(Dialog.java:259)
    at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
    at com.phonegap.DroidGap$GapClient.onJsAlert(DroidGap.java:983)
    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:531)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4632)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit
    $MethodAndArgsCaller.run(ZygoteInit.java:871)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    at dalvik.system.NativeStart.main(Native Method)
    ERROR/(1364): Dumpstate > /data/log/dumpstate_app_error

Please kindly guide me where i am wrong.Thanks in advance. 请好心指导我哪里错了。谢谢。

 android.os.BinderProxy@48c59828 is not valid; is your activity running? 

This error mostly occurs when you are trying to close/finish the Activity when some ProgressDialog is running. 当您尝试在某些ProgressDialog运行时close/finish活动时,通常会发生此错误。 So, you are trying to finish() Activity before dismissing Progress Dialog. 因此,您正在尝试在关闭进度对话框之前finish()活动。 You should first try to dismiss the ProgressDialog then finish the Activity. 您应该首先尝试关闭ProgressDialog,然后完成Activity。

Check if the activity is finishing before showing that dialog. 在显示该对话框之前,请检查活动是否完成。

if (!isFinishing()) {
    showDialog(MY_DIALOG);
}

The crash occurs when a background thread tries to show a dialog just when the UI thread is exiting. 当后台线程正试图在退出UI线程时显示对话框时,发生崩溃。

$BadTokenException: $ BadTokenException:

this type of error because of context problem. 由于上下文问题而导致的此类错误。 pass proper context in your code, 在您的代码中传递适当的上下文,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM