4 messages in com.googlegroups.android-developersRe: Freezing app after ProgressDialog...
FromSent OnAttachments
MarcJ28 Dec 2007 02:07 
Evan JIANG28 Dec 2007 02:56 
MarcJ28 Dec 2007 04:19 
MarcJ02 Jan 2008 00:06 
Subject:Re: Freezing app after ProgressDialog finishes
From:MarcJ (marc@gmail.com)
Date:12/28/2007 04:19:07 AM
List:com.googlegroups.android-developers

I know, but adding the Handler makes the problem worse. Now it always freezes. Only in debug mode everything works perfectly.

Marc

On Dec 28, 11:56 am, Evan JIANG <firs@gmail.com> wrote:

Hi,     I think you may not do UI operation in another thread. Add a handler to change the UI. Regards, Evan JIANG

On Fri, 28 Dec 2007, MarcJ wrote:

Date: Fri, 28 Dec 2007 02:07:59 -0800 (PST) From: MarcJ <marc@gmail.com> Reply-To: andr@googlegroups.com To: Android Developers <andr@googlegroups.com> Subject: [android-developers] Freezing app after ProgressDialog finishes

Hi!

I hope someone can explain this weird behaviour to me. I have a simple example activity with one button and when this button is pressed I want to show a running progress dialog. This work well most of the times, but sometimes the application freezes completely, and the emulator stops responding. Sometimes killing the activity by pressing the red button helps, but I've had to restart the emulator several times.

This is the code that I use:

import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;

public class TestActivity extends Activity implements OnClickListener {    private Button loadButton;

   @Override    protected void onCreate(Bundle icicle) {            super.onCreate(icicle);

           setContentView(R.layout.rss);

           loadButton = (Button) findViewById(R.id.startButton);            loadButton.setOnClickListener(this);    }

   public void onClick(View view) {            if (view == loadButton) {                    new Loader(ProgressDialog.show(this, null, "Doing stuff",
false, true)).start();            }    }

   private class Loader extends Thread implements OnCancelListener {

           private boolean cancelled = false;

           private final ProgressDialog dialog;

           public Loader(ProgressDialog dialog) {                    this.dialog = dialog;                    dialog.setCancelListener(this);            }

           public void run() {                    dialog.setProgress(0);                    for (int i = 0; i < 10000; i += 50) {                            dialog.setProgress(i);                            try {                                    Thread.sleep(10);                            } catch (InterruptedException e) {                                    break;                            }                            if (cancelled)                                    break;                    }                    dialog.dismiss();            }

           public void onCancel(DialogInterface arg0) {                    cancelled = true;            }    } }

After the dialog.dismiss() is called, the application hangs. But when I start a debugging session, the application never freezes, so I think that there is some kind of deadlock somewhere.