首页 > 代码库 > android hander 线程用法
android hander 线程用法
@Override public void onClick(View v) { lsh = "576"; startdate = setstart_date.getText().toString(); enddate = setend_date.getText().toString(); btnLoginContext = v.getContext(); HandlerThread handlerThread = new HandlerThread("handlerThread"); handlerThread.start();// 启新线程 MyHandler myHandler = new MyHandler(handlerThread.getLooper());// 建消息队列的处理器(新线程) Message msg = myHandler.obtainMessage();// 绑定自定义的处理器 Bundle bundle = new Bundle(); bundle.putString("startdate", startdate); bundle.putString("enddate", enddate); bundle.putString("lsh", lsh); msg.setData(bundle); msg.sendToTarget(); } @Override public void handleMessage(Message msg) { try { super.handleMessage(msg); Bundle bundle = msg.getData(); if (bundle == null) return; String result = ""; StringBuilder str = new StringBuilder(); str.append("<condition><ksrqsj>" + bundle.get("startdate").toString()+ "</ksrqsj>"); str.append("<jsrqsj>" + bundle.get("enddate").toString()+ "</jsrqsj>"); str.append("<lsh>" + bundle.get("lsh").toString()+ "</lsh></condition>"); RequireParams params = new RequireParams(); params.setMethodName("GetNurseTableinfoPag"); WebServiceInvoker invoker = new WebServiceInvoker(); invoker.setParams(params); //设置参数 SoapObject request = invoker.getRequestInstance(); request.addProperty("condition", str.toString()); request.addProperty("recBegin", 0); request.addProperty("recEnd", 10); result = invoker.invokeWS(request).getProperty(0).toString(); if (result.indexOf("error") >= 0) { showMyDialog(btnLoginContext, result); return; } else { List<Map<String, Object>> myNurseInfos = null; myNurseInfos = NurseInfo.getNurseInfo(result, "UTF-8"); //查询成功 Intent intent = new Intent(); Bundle mybundle = new Bundle(); final SerializableMaplist myMap=new SerializableMaplist(); myMap.setMap(myNurseInfos); mybundle.putSerializable("listdata", myMap); intent.putExtras(mybundle); intent.setClass(getActivity(), NursingPageQuery.class); startActivity(intent); } } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); Toast.makeText(getActivity(),"错误:"+ Log.getStackTraceString(e),Toast.LENGTH_LONG).show(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。