Android ProgressDialog 最佳处理方式

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(){
                                       //也有用这方法的,但在特别的情况下会抛出异常
                                    }
                                }
	}

 

你可能感兴趣的:(thread,android)