電話のデータベースにメッセージを問い合わせるアプリがあります。カーソルにメッセージが含まれている場合は、アラートダイアログに各メッセージを次々に表示しようとしています。ウィンドウリークが発生したというエラーが表示されます。
次が表示される前にalertdialogが適切にキャンセルされなかったことが関係していると思います。なぜ私がこのエラーを受け取るのか誰かが知っていますか?
@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)