ProgressDialog does not always show up
<p>My application works as a BluetoothServer, almost the same as the <code>BluetoothChat example</code>. I'm facing a strange problem. Inside my run-method where I start reading input from the bluetoothSocket, I want to post a message to a handler. This handler is in a seperate class, to avoid possible memory leaks.   </p>

<pre><code>public void run() {
    Log.i("", "BEGIN ReadInputThread");
    final byte[] buffer = new byte[1024];
    int bytesread;

    Message msg = handler.obtainMessage();
    msg.obj = "0";
    handler.sendMessage(msg);
    ...... snip .....
</code></pre>

<p>When I receive the String "0", in my handler, I want to show a progressDialog that informing the user that the application has an incoming file. In my handler, this is how I deal with it:</p>

<pre><code>public class MessageHandler extends Handler {

    @Override
    public void handleMessage(Message m) {

        Vibrator v = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
        String message = (String) m.obj;

        //Getting files
        if (message.equals("0")) {

            folder.appendToLogFile(new Date().toString(), "Incoming File From: " + deviceName); 
            v.vibrate(1500);
            pd = new ProgressDialog(c);
            pd.setTitle("Please Wait..");
            pd.setMessage("Retrieving file from " + deviceName);
            pd.setCancelable(false);
            pd.show();
        }
}
</code></pre>

<p>The first time, when I have my Activity open, which will start this Thread, the progressDialog will show. After the transfer has finished, I navigate to a new Activity, and then returning to the previous Activity. When I now try to transfer a file, it will succeed, but no ProgressDialog is shown on the screen. </p>

<p>I did some checks just to figure out if the ProgressDialog is "visible" by adding these two lines under the <code>pd.show() statement</code></p>

<pre><code>if(pd.isShowing())
    Log.w("Handler: ", "inside the handler, and the progressdialog is showing");
</code></pre>

<p>And this also appears in LogCat, even if the ProgressDialog is not showing! </p>

<p>Can anybody give me a hint, or a solution to this frustration issue? </p>

<p>Thanks in advance!</p>

<hr>

<p><strong>Just to clarify a bit</strong></p>

<p>My ProgressDialog is created in a class which not extends Activity, it doesn't extend any classes. 
The first thing I do, is to post a 0 to my handler, in the start of my <code>run() method</code>. When I know that I have received the last byte-packet from the socket, I send another message to the handler:</p>

<pre><code>if(lastPacket) {
    msg = handler.obtainMessage();
    msg.obj = "1";  
    handler.sendMessage(msg);                                                    
}
</code></pre>

<p>And in my Handler:</p>

<pre><code>@Override
    public void handleMessage(Message m) {

        Vibrator v = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
        String message = (String) m.obj;

        //Getting files
        if (message.equals("0")) {

            folder.appendToLogFile(new Date().toString(), "Incoming File From: " + deviceName); 
            v.vibrate(1500);
            pd = new ProgressDialog(c);
            pd.setTitle("Please Wait..");
            pd.setMessage("Retrieving file from " + deviceName);
            pd.setCancelable(false);
            pd.show();
            if(pd.isShowing())
                Log.w("Handler: ", "inside the handler, and the progressdialog is showing");


        }

        //File complete 
        if(message.equals("1")) {

            Toast.makeText(c, "File Received from: " + deviceName, Toast.LENGTH_LONG).show();
            folder.appendToLogFile(new Date().toString(), "File Received"); 
            pd.setMessage(c.getResources().getString(R.string.createCase));

            GenerateCase caseGenerator = new GenerateCase(c, pd, lastCases, nextPCN);
            caseGenerator.execute("");
        }
    }
</code></pre>

<p>as you can see, I pass the ProgressDialog into the AsyncTask. In my <code>onPostExecute</code> method, I dismiss this <code>ProgressDialog</code></p>

<h2>Solution</h2>

<p>If someone is curious. I got confused with the threads. When I left my Activity, I forgot to kill my running thread, which would cause the ProgressDialog to start in a different thread when I resumed my activity. </p>
