---
title: "Android ProgressDialog 最佳处理方式"
author: "fonter"
date: "2010-06-30T14:10:07Z"
tags: []
categories: ["移动开发"]
slug: "android-progressdialog"
draft: false
lastmod: "2010-08-28T12:10:50Z"
id: 702508
url: "https://fonter.iteye.com/blog/702508"
---

Android ProgressDialog 处理方式，在经过测试后，以下方法比较好

 

```
 private void initProgressDialog() {
  progressDialog = new ProgressDialog(this);
  progressDialog.setMessage(getString(R.string.progress));
  progressDialog.show();
  mHandler.postDelayed(runnable,1);
 }
```

 

```
	private Runnable runnable = new Runnable() {   
		  
	    public void run() {   
			list = getFireAppInfo();
			networkAppAdapter = new NetworkAppAdapter(getBaseContext(),
					list);
			networkfilterList.setAdapter(networkAppAdapter);
			MessageHandlerUtil.sendMessageToHandler(mHandler, 1);
	    }   
	  
	}; 
```

 

```
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (progressDialog != null)
					progressDialog.dismiss();
				break;
			}
		}
	};
```

  

也有用下面的方法，但在特别的情况下会抛出异常

 

```
                private ProgressDialog progressDialog;
	private void initProgressDialog() {
		progressDialog = new ProgressDialog(this);
		progressDialog.setMessage("Progress..");
		progressDialog.show();
		new Thread(){
                                    public void run(){
                                       //也有用这方法的，但在特别的情况下会抛出异常
                                    }
                                }
	}
```