【已解决】Activity MainActivity has leaked window PhoneWindow$DecorView@ that was originally added here


今天写Sqlite Demo时,发生如下错误:


Activity me.dengfengdecao.android.savedatademo.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@536caa40 that was originally added 

here


anager: android.view.WindowLeaked: Activity me.dengfengdecao.android.savedatademo.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow

$DecorView@536caa40 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.view.Window$LocalWindowManager.addView(Window.java:547)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.app.Dialog.show(Dialog.java:277)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at me.dengfengdecao.android.savedatademo.MainActivity

$MyAsyncTask.onPreExecute(MainActivity.java:139)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.os.AsyncTask.execute(AsyncTask.java:534)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at me.dengfengdecao.android.savedatademo.MainActivity$7.onClick

(MainActivity.java:123)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.view.View.performClick(View.java:4084)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.view.View$PerformClick.run(View.java:16966)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.os.Handler.handleCallback(Handler.java:615)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.os.Handler.dispatchMessage(Handler.java:92)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.os.Looper.loop(Looper.java:137)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at java.lang.reflect.Method.invokeNative(Native Method)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at java.lang.reflect.Method.invoke(Method.java:511)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run

(ZygoteInit.java:786)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-10 21:19:53.131 22077-22077/me.dengfengdecao.android.savedatademo E/WindowManager:     at dalvik.system.NativeStart.main(Native Method)


原因是,app执行插入sql语句时语法出现错误,导致app崩溃,进而导致之前显示的进度条(ProgressDialog)没有关闭,而出现的窗口泄露问题,只要在


onStop方法中添加以下语句即可避免此错误:


@Override
    protected void onStop() {
        super.onStop();

        if (mProgressDialog.isShowing())
            mProgressDialog.dismiss();

    }


参考:http://blog.sina.com.cn/s/blog_a72ec20c0101exei.html

你可能感兴趣的:(window,leaked)