WindowLeaked exception with progressdialog
<p>I try to make it simple, even though it is not. I query the phone's calllog into arrays.Then I put these arrays into an sql table. So now I have a the callog in a table.
Then I query the oldest and newest call record. This all happens in a progressdialog.</p>

<p>My problem is this error:</p>

<pre><code>06-06 21:24:34.954: E/AndroidRuntime(973): java.lang.NumberFormatException: Invalid long: ""
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.invalidLong(Long.java:125)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.parseLong(Long.java:346)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.parseLong(Long.java:319)
06-06 21:24:34.954: E/AndroidRuntime(973):  at com.b2creative.b2callstats.Calllogs$8.run(Calllogs.java:503)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Thread.run(Thread.java:856)
06-06 21:24:37.860: E/WindowManager(973): Activity com.b2creative.b2callstats.Calllogs has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412e1fb0 that was originally added here
06-06 21:24:37.860: E/WindowManager(973): android.view.WindowLeaked: Activity com.b2creative.b2callstats.Calllogs has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412e1fb0 that was originally added here
06-06 21:24:37.860: E/WindowManager(973):   at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:344)
06-06 21:24:37.860: E/WindowManager(973):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-06 21:24:37.860: E/WindowManager(973):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
</code></pre>

<p>I read that the WindowLeaked exception in the log usually happens when you have some sort of async task that is finishing after the activity that began it is destroyed., and I also read that the real problem should be somewhat earlier: that invalid long error!</p>

<p>So I logged the important parts and it turned out that nothing is happening while the progress dialog is active. My arrays are empty, and so is my table. The long problem is caused by a string which is = "", because there was no data to add the string a value. In short:</p>

<p>This all happened when I changed the targetSdkVersion to 13 (3.2).
In API level 7 (2.1) the problem did not occur.</p>

<p><strong>Here you see the problematic part:</strong></p>

<pre><code>          pd = ProgressDialog.show(Calllogs.this, "Please wait..", "Loading data. This may take a few" +
                    " seconds based on the number of calls.", false, true);


            Thread thread = new Thread(new Runnable() {  
                   public void run() {


    //query calllog into arrays, populating table, getting date of the last and first added record, but nothing seems to be happening


//here comes the error:
 String dA = "";
                HotOrNot infod = new HotOrNot(Calllogs.this);
                infod.open();
                Cursor cursorA = infod.getAllTitles_DateLimit1("DESC");
                 if (cursorA.moveToFirst())
                 {
                 do{
                    dA = cursorA.getString(5);
                }while (cursorA.moveToNext());
                }

                Log.i("dA", dA + ""); //null
                d1= dA;
                infod.close();
    cal1.setTimeInMillis(Long.parseLong(dA));  //this is the first error. it looks like the table is empty.



                handler.sendEmptyMessage(0);

            lv1.post(new Runnable() {
                public void run() {
                 lv1.setAdapter(adapter);
              }}); 

                   }
                   });


                   thread.start();
</code></pre>

<p>I added</p>

<pre><code>@Override
protected void onStop() {
 super.onStop();
 if (pd != null) {
   }
 pd.dismiss();
 pd = null;
 }
</code></pre>

<p>and I also added this code to the onDestroy and onPause methods, but in vain.</p>

<p>So basically to me this means that that variable the logcat points to has no value (at least not a value that can be converted to a Long type), because the activity finishes due to something, and the leakwindow error occurs because the activity finished but the progress dialog is on. Or the activity finishes because the variable has improper value, but the progressdialog is still on, why? Devil's circle, any ideas?</p>
