bundle handler.sendMessage 方法及接收数据方法

bundle handler.sendMessage 方法及接收数据方法

添加传递数据:

new Thread(new Runnable() {
	    			@Override
	    			public void run() {
	    				Message message = Message.obtain();
	    				message.what=SHOW_RESPONSE;
					Bundle bundle = new Bundle();  
	    				bundle.putString("city", city);
	    				bundle.putString("date", date);
	    				bundle.putString("type", type);
	    				bundle.putString("fengxiang", fengxiang);
	    				bundle.putString("fengli", fengli);
	    				bundle.putString("high", high);
	    				bundle.putString("low", low);
	    				message.setData(bundle);  
	    				handler.sendMessage(message);
	    			}
	    		}).start();

接收数据:

handler = new Handler() {
				public void handleMessage(Message msg) {
					switch (msg.what) {
					case SHOW_RESPONSE:
						String city = (String) msg.getData().get("city");
						String date = (String) msg.getData().get("date");
						String fengxiang = (String) msg.getData().get("fengxiang");
						String fengli = (String) msg.getData().get("fengli");
						String high = (String) msg.getData().get("high");
						String type = (String) msg.getData().get("type");
						String low = (String) msg.getData().get("low");
						Log.d("show",date+":"+type+":"+fengxiang+":"+fengli+":"+low+":"+high);
						break;
					default:
						break;
					}
				}
			};


你可能感兴趣的:(Android)