private class MyHandler extends Handler {
//弱引用防止内存泄漏
WeakReferencem Activity;
public MyHandler(MainActivity activity){
mActivity=newWeakReference(activity);
}
public void handleMessage(android.os.Message msg) {
MainActivity activity =mActivity.get();
switch(msg.what) {
caseERROR:
Toast.makeText(activity,"网络异常",Toast.LENGTH_SHORT).show();
break;
caseERROR_CITY:
String str = (String) msg.obj;
urlLog.setText(str);
Toast.makeText(activity,"检查url是否正确",Toast.LENGTH_SHORT).show();
break;
caseSUCCESS:
String strw = (String) msg.obj;
urlLog.setText(strw);
break;
caseTIMEOK:
String strTime = (String) msg.obj;
time.setText(strTime);
break;
caseMD5:
String md = (String) msg.obj;
urlLog.setText(md);
break;
}
}
}