在使用ProgressDialog的时候,有可能会遇到“Activity has leaked window that was originally added”的错误,原因是ProgresDialog是在Activity基础上显示出来的,
(我是这么理解的),也就是Activity是ProgressDialog的“父窗体”,“父窗体”都没了,再次调用dialog.show()的时候,肯定报错了。解决方法也很简单。在onPause中
加上dismiss就可以了。
//TODO ADD by lihu 防止崩溃
@Override
protected void onPause() {
super.onPause();
if (mPD != null && !this.isFinishing()) {
mPD.dismiss();
}
}
01-15 09:50:32.077: E/WindowManager(3787): Activity io.vov.vitamio.activity.InitActivity
has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405e18c0
that was originally added here
01-15 09:50:32.077: E/WindowManager(3787): android.view.WindowLeaked: Activity io.vov.vitamio.activity.InitActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405e18c0 that was originally added here
01-15 09:50:32.077: E/WindowManager(3787): at android.view.ViewRoot.<init>(ViewRoot.java:259)
01-15 09:50:32.077: E/WindowManager(3787): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-15 09:50:32.077: E/WindowManager(3787): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-15 09:50:32.077: E/WindowManager(3787): at android.view.Window$LocalWindowManager.addView(Window.java:465)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.Dialog.show(Dialog.java:241)
01-15 09:50:32.077: E/WindowManager(3787): at io.vov.vitamio.activity.InitActivity$1.onPreExecute(InitActivity.java:50)
01-15 09:50:32.077: E/WindowManager(3787): at android.os.AsyncTask.execute(AsyncTask.java:391)
01-15 09:50:32.077: E/WindowManager(3787): at io.vov.vitamio.activity.InitActivity.onCreate(InitActivity.java:65)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
01-15 09:50:32.077: E/WindowManager(3787): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 09:50:32.077: E/WindowManager(3787): at android.os.Looper.loop(Looper.java:130)
01-15 09:50:32.077: E/WindowManager(3787): at android.app.ActivityThread.main(ActivityThread.java:3835)
01-15 09:50:32.077: E/WindowManager(3787): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 09:50:32.077: E/WindowManager(3787): at java.lang.reflect.Method.invoke(Method.java:507)
01-15 09:50:32.077: E/WindowManager(3787): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
01-15 09:50:32.077: E/WindowManager(3787): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
01-15 09:50:32.077: E/WindowManager(3787): at dalvik.system.NativeStart.main(Native Method)
01-15 09:50:32.139: D/dalvikvm(3787): GC_EXTERNAL_ALLOC freed 179K, 47% free 3283K/6151K, external 2009K/2099K, paused 41ms