I am developing in app where I am using an activity in which I’m displaying a list view items page by page by using threading, When the user selects the item it will take the user to another activity.
But Here some times when I click on list view item the app crashes. It says something in log cat but I am unable to understand it.
Here is the Stack Trace:
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): FATAL EXCEPTION: main
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4073ef78 is not valid; is your activity running?
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.view.ViewRoot.setView(ViewRoot.java:527)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.view.Window$LocalWindowManager.addView(Window.java:424)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.app.Dialog.show(Dialog.java:241)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.usablenet.mobile.walgreen.app.util.ErrorAlertServiceImp.showErrorAlert(ErrorAlertServiceImp.java:86)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.usablenet.mobile.walgreen.pharmacy.PrescriptionList.showErrorCodeAlert(PrescriptionList.java:360)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.usablenet.mobile.walgreen.pharmacy.PrescriptionList.access$300(PrescriptionList.java:45)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.usablenet.mobile.walgreen.pharmacy.PrescriptionList$2.handleMessage(PrescriptionList.java:323)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.os.Looper.loop(Looper.java:130)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at java.lang.reflect.Method.invoke(Method.java:507)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-24 16:26:44.320: ERROR/AndroidRuntime(4248): at dalvik.system.NativeStart.main(Native Method)
Thanks,
Balu.
Use
getApplicationContextfor the AlertDialog, otherwise you will get this error when you switch between tasks.Instead of:
AlertDialog.Builder builder = new AlertDialog.Builder(this);Use:
ConnectionDetector = new ConnectionDetector(getApplicationContext());The same goes for any listeners on the dialog.
Furthermore: