首页 > 代码库 > Android中Handler使用

Android中Handler使用

使用:

	Bundle bundle = new Bundle();
	Message message = dummyHandler.obtainMessage(EVENT_SET_LOCK_CLICK);
	message.arg1 = 101;
	bundle.putString("lockList", lockList);
	message.setData(bundle);
	dummyHandler.sendMessage(message);

这里obtainMessage相当于message.what= ...

message.arg1相当于简易参数

sendMessage进行调用

Handler内部处理:

private  Handler dummyHandler = new Handler() {  
		public void handleMessage(Message msg) {  
		switch(msg.what){
			case EVENT_SET_LOCK_CLICK:
			int arg_1 = msg.arg1;
			Bundle bundle = msg.getData();
			String lockList = bundle.getString("lockList");
		}
	}
   }


Android中Handler使用