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

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.