Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); Bundle data = msg.getData(); String val = data.getString("value"); Toast.makeText(MainActivity.this, "获得的结果是:"+val, Toast.LENGTH_SHORT).show(); } };
Runnable networkTask = new Runnable() { @Override public void run() { // TODO // 在这里进行 http request.网络请求相关操作 GetServiceJsonData getJson=new GetServiceJsonData(); String getStr = getJson.getServerInfo(""); Message msg = new Message(); Bundle data = new Bundle(); data.putString("value", getStr); msg.setData(data); handler.sendMessage(msg); } };