1

我有一个应用程序可以查询手机的数据库以获取消息。如果光标返回其中包含消息,那么我将尝试在警报对话框中一个接一个地显示每条消息。我收到以下错误消息,表明存在窗口泄漏。

我认为这与在显示下一个之前未正确取消警报对话框有关。有谁知道我为什么会收到这个错误?

@Override
    protected void onResume() {
        super.onResume();
      Cursor c = nfcScannerApplication.loginValidate.queryAllFromMessage();

        Log.e(TAG, "messages in db = " +  c.getCount());


            if(c != null && c.getCount() > 0){
                c.moveToFirst();

                while(c.moveToNext()){

                final String guid = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_GUID));
                final String message = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_TEXT));
                final String createdAt = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_CREATED_AT));
                final String sender = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_SENDER));


                DateTime dt = new DateTime(createdAt);
                DateTimeFormatter fmt2 = DateTimeFormat.forPattern("H:mm d-MMM-Y");
                String date = fmt2.print(dt);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        this);

                    // set title
               alertDialogBuilder.setTitle("You have a new message : " );

                    // set dialog message
                    alertDialogBuilder
                        .setMessage(  "\n" + message + "\n"
                                + "From : " + sender + " at " + date + "\n"+"Click OK to confirm message read")
                        .setCancelable(false)
                        .setPositiveButton("Ok",new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,int id) {


                                nfcScannerApplication.loginValidate.deleteMessage(guid);

                                Cursor c = nfcScannerApplication.loginValidate.queryAllFromMessage();
                                Log.e(TAG, "message count = " + c.getCount());

                                //send guid back to martin so he can delete message on server
                                String[] params = new String[]{guid};
                                AsyncCompleteMessage ascm = new AsyncCompleteMessage();
                                ascm.execute(params);

                                finish();

                            }
                          });

                        // create alert dialog
                        AlertDialog alertDialog = alertDialogBuilder.create(); 

                        // show it
                        alertDialog.show();

                }//end of while
            }else{

                finish();
            }

    }

.

02-13 11:33:13.602: E/WindowManager(19605): Activity com.carefreegroup.DisplayMessageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@418e0ac8 that was originally added here
02-13 11:33:13.602: E/WindowManager(19605): android.view.WindowLeaked: Activity com.carefreegroup.DisplayMessageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@418e0ac8 that was originally added here
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:465)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.Window$LocalWindowManager.addView(Window.java:558)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Dialog.show(Dialog.java:282)
02-13 11:33:13.602: E/WindowManager(19605):     at com.carefreegroup.DisplayMessageActivity.onResume(DisplayMessageActivity.java:103)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Activity.performResume(Activity.java:5148)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2997)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3055)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.access$600(ActivityThread.java:151)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
02-13 11:33:13.602: E/WindowManager(19605):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 11:33:13.602: E/WindowManager(19605):     at android.os.Looper.loop(Looper.java:155)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.main(ActivityThread.java:5485)
02-13 11:33:13.602: E/WindowManager(19605):     at java.lang.reflect.Method.invokeNative(Native Method)
02-13 11:33:13.602: E/WindowManager(19605):     at java.lang.reflect.Method.invoke(Method.java:511)
02-13 11:33:13.602: E/WindowManager(19605):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
02-13 11:33:13.602: E/WindowManager(19605):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
02-13 11:33:13.602: E/WindowManager(19605):     at dalvik.system.NativeStart.main(Native Method)
02-13 11:33:13.602: E/WindowManager(19605): Activity com.carefreegroup.DisplayMessageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4152c258 that was originally added here
02-13 11:33:13.602: E/WindowManager(19605): android.view.WindowLeaked: Activity com.carefreegroup.DisplayMessageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4152c258 that was originally added here
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:465)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
02-13 11:33:13.602: E/WindowManager(19605):     at android.view.Window$LocalWindowManager.addView(Window.java:558)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Dialog.show(Dialog.java:282)
02-13 11:33:13.602: E/WindowManager(19605):     at com.carefreegroup.DisplayMessageActivity.onResume(DisplayMessageActivity.java:103)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.Activity.performResume(Activity.java:5148)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2997)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3055)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.access$600(ActivityThread.java:151)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
02-13 11:33:13.602: E/WindowManager(19605):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 11:33:13.602: E/WindowManager(19605):     at android.os.Looper.loop(Looper.java:155)
02-13 11:33:13.602: E/WindowManager(19605):     at android.app.ActivityThread.main(ActivityThread.java:5485)
02-13 11:33:13.602: E/WindowManager(19605):     at java.lang.reflect.Method.invokeNative(Native Method)
02-13 11:33:13.602: E/WindowManager(19605):     at java.lang.reflect.Method.invoke(Method.java:511)
02-13 11:33:13.602: E/WindowManager(19605):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
02-13 11:33:13.602: E/WindowManager(19605):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
02-13 11:33:13.602: E/WindowManager(19605):     at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

5

在调用您的方法dialog.dismiss();之前尝试调用,如下面的代码所示。finish()onClick()

public void onClick(DialogInterface dialog,int id) {


                            nfcScannerApplication.loginValidate.deleteMessage(guid);

                            Cursor c = nfcScannerApplication.loginValidate.queryAllFromMessage();
                            Log.e(TAG, "message count = " + c.getCount());

                            //send guid back to martin so he can delete message on server
                            String[] params = new String[]{guid};
                            AsyncCompleteMessage ascm = new AsyncCompleteMessage();
                            ascm.execute(params);

                            dialog.dismiss();
                            finish();

                        }
于 2013-02-13T11:40:03.177 回答
0

退出活动后,您正试图显示一个对话框。检查此链接。

于 2013-02-13T11:41:05.767 回答