Saturday, January 21, 2012

How to display a progress message aka "hourglass" in Android around long running tasks, really moving that long running tasks to a different thread but obstructing your activity with a curtain from progress so messages are processed and everything shows. Here is a snippet:


ProgressDialog dialog = ProgressDialog.show(this, "Title",
"Your message", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialog.dismiss();

}
};

Thread export = new Thread() {
public void run() {

// LONG TASK CALL
// callLongTask();

handler.sendEmptyMessage(0);
}
};
export.start();