0

When i call my func for deleting a row from my DB :

public void deleteRow(int rowId) {
     getWritableDatabase().delete(DatabaseHelper.orderTable, "id="+rowId,null);

i get a lot of error messages in the logcat :

06-02 16:32:14.356: E/WindowManager(2770): Activity com.Sagi.MyOrders.FindOrder has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f50540 that was originally added here
06-02 16:32:14.356: E/WindowManager(2770): android.view.WindowLeaked: Activity com.Sagi.MyOrders.FindOrder has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f50540 that was originally added here
06-02 16:32:14.356: E/WindowManager(2770):  at android.view.ViewRoot.<init>(ViewRoot.java:247)
06-02 16:32:14.356: E/WindowManager(2770):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
06-02 16:32:14.356: E/WindowManager(2770):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-02 16:32:14.356: E/WindowManager(2770):  at  android.view.Window$LocalWindowManager.addView(Window.java:424)
06-02 16:32:14.356: E/WindowManager(2770):  at android.app.Dialog.show(Dialog.java:241)
06-02 16:32:14.356: E/WindowManager(2770):  at com.Sagi.MyOrders.FindOrder.alert_editlist(FindOrder.java:56)
06-02 16:32:14.356: E/WindowManager(2770):  at com.Sagi.MyOrders.FindOrder.onItemLongClick(FindOrder.java:138)
06-02 16:32:14.356: E/WindowManager(2770):  at android.widget.AbsListView.performLongPress(AbsListView.java:1753)
06-02 16:32:14.356: E/WindowManager(2770):  at android.widget.AbsListView.access$600(AbsListView.java:72)
06-02 16:32:14.356: E/WindowManager(2770):  at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:1711)
06-02 16:32:14.356: E/WindowManager(2770):  at android.os.Handler.handleCallback(Handler.java:587)
06-02 16:32:14.356: E/WindowManager(2770):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-02 16:32:14.356: E/WindowManager(2770):  at android.os.Looper.loop(Looper.java:123)
06-02 16:32:14.356: E/WindowManager(2770):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 16:32:14.356: E/WindowManager(2770):  at java.lang.reflect.Method.invokeNative(Native Method)
06-02 16:32:14.356: E/WindowManager(2770):  at java.lang.reflect.Method.invoke(Method.java:521)
06-02 16:32:14.356: E/WindowManager(2770):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-02 16:32:14.356: E/WindowManager(2770):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-02 16:32:14.356: E/WindowManager(2770):  at dalvik.system.NativeStart.main(Native Method)

I looked for a cursor left open or a DB but there is nothing i could find. right after the function returns, there is :

finish();

Here is my alertDialog creator :

private void alert_editlist(final int id) {
        // TODO Auto-generated method stub
        final CharSequence[] items = {"Edit", "Delete"};

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("What do you want to do?");
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (items[item]=="Edit") {
                }
                else if(items[item]=="Delete"){
                   finish();
                }
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

Thanks you !!!

SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • There's something wrong with your dialog handling, not the SQLite command. Leaking a window happens when, say, you have a dialog window open and rotate your device. Handing dialogs through activity recreation can be tricky. What are you doing with dialogs here? at `com.Sagi.MyOrders.FindOrder.alert_editlist(FindOrder.java:56)` – Phix Jun 02 '12 at 16:39
  • Edit : added my dialog creator. – SagiLow Jun 02 '12 at 16:49
  • http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added – Samir Mangroliya Jun 02 '12 at 16:50
  • add here where you creating listView etc. – Simon Dorociak Jun 02 '12 at 16:51
  • as i understand the problem is i want the record to be deleted as the user presses the Delete button, but if finish() is not called, the dialog will stay open. How can i change the dialog so whenever the Delete button will be clicked, it will call a function and close the dialog ? – SagiLow Jun 02 '12 at 16:59

1 Answers1

0

You close a dialog with dismiss();

Change finish(); to dismiss() (insert your delete method call before it) and you should get better results.

Barak
  • 16,318
  • 9
  • 52
  • 84