谈实现Android定时执行

方式1:Timer

 

在项目中测试,效果不佳;

 

方式2: Handler

 

启动任务:

 

handler.postDelayed(runnable, 3000);

 取消任务:

 

handler.removeCallbacks(runnable);

 定义任务:

 

	Runnable runnable = new Runnable(){
		@Override
		public void run() {
			handler.postDelayed(this, 3000);
			// TODO Auto-generated method stub
			beanList = RemoteService.parseLogisticsBean(param);
			if(beanList==null){
				beanList = new ArrayList<HashMap<String, String>>();
			}else{
				adapter.notifyDataSetChanged();
			}
		}

 

你可能感兴趣的:(谈实现Android定时执行)