@Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); // timer.cancel(); task.stop(); }
public void openAutoLoad() { /*timer=new Timer(); final GsonServlet<GetChatRecordReq, GetChatRecordRes> gServlet=new GsonServlet<GetChatRecordReq, GetChatRecordRes>(mContext); timer.schedule(new TimerTask() { @Override public void run() { fillData(gServlet); Log.d("dd","hello world!"); } }, 1000,5000);*/ task = new HttpTask<GetChatRecordReq, GetChatRecordRes>(mContext); GetChatRecordReq req = new GetChatRecordReq(); req.setDoctor_id(doctor_id); req.setPatient_id_card(patient_id); task.start(req, GetChatRecordRes.class); task.setOnResponseListening( new OnResponseListening<GetChatRecordReq, GetChatRecordRes>() { public void onResponseSuccess(GetChatRecordRes commonRes) { if (commonRes != null) { HashMap<String, ChatContent> doctor_content = commonRes.getDoctor_content(); List<PatientChatContent> patient_content = commonRes.getPatient_content(); if (patient_content.size() > 0) { String chatId = patient_content.get(patient_content.size() - 1).getChatId(); int mSize = doctor_content.size(); // 新的消息过来 if (!lastContentId.equals(chatId) || size != mSize) { if (adapter == null) { adapter = new ChatAdapter(mContext, patient_content, doctor_content); chat_record_list.setAdapter(adapter); } else { adapter.updateData(patient_content, doctor_content); } // chat_record_list.setAdapter(adapter); chat_record_list.setSelection(patient_content.size() - 1); size = mSize; lastContentId = chatId; } } } } }); }