Crash:ProgressDialog does not dismiss,but activity is destory

Crash:ProgressDialog doesn't dismiss,but activity is destory 

Exception information:

  
  
  
  
  1. 09-26 13:48:01.777: E/AndroidRuntime(9523): FATAL EXCEPTION: main 
  2. 09-26 13:48:01.777: E/AndroidRuntime(9523): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4078a5e8 is not valid; is your activity running? 
  3. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.view.ViewRoot.setView(ViewRoot.java:529
  4. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177
  5. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91
  6. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.view.Window$LocalWindowManager.addView(Window.java:424
  7. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.app.Dialog.show(Dialog.java:241
  8. 09-26 13:48:01.777: E/AndroidRuntime(9523): at 包名及方法名(Unknown Source) 
  9. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:281
  10. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.os.Handler.dispatchMessage(Handler.java:99
  11. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.os.Looper.loop(Looper.java:130
  12. 09-26 13:48:01.777: E/AndroidRuntime(9523): at android.app.ActivityThread.main(ActivityThread.java:3694
  13. 09-26 13:48:01.777: E/AndroidRuntime(9523): at java.lang.reflect.Method.invokeNative(Native Method) 
  14. 09-26 13:48:01.777: E/AndroidRuntime(9523): at java.lang.reflect.Method.invoke(Method.java:507
  15. 09-26 13:48:01.777: E/AndroidRuntime(9523): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841
  16. 09-26 13:48:01.777: E/AndroidRuntime(9523): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599
  17. 09-26 13:48:01.777: E/AndroidRuntime(9523): at dalvik.system.NativeStart.main(Native Method) 

解决方法:

如果不是Activity强转成Activity,否则直接判断isFinishing()方法。

  
  
  
  
  1. try
  2. if(((Activity)Context).isFinishing() == false){ 
  3. xxx.show(); 
  4.  
  5. }catch(Exception e){  
  6. e.printStackTrace(); 

 

 

你可能感兴趣的:(Activity,ProgressDialog,destory,dissmiss)