android开子线程避免出现main错误

Runnable SonThread=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
String tem = GetInfoExec();
//Log.i("suerinfo",tem);
Message mes = new Message();
mes.obj = tem;
//handler.sendMessage(mes);
mHandler.sendMessage(mes);
}
};
private static class MyHandler extends Handler{
private final WeakReference<UserInfoPage> mActivity;
public MyHandler(UserInfoPage activity) {
mActivity = new WeakReference<UserInfoPage>(activity);
}

@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
UserInfoPage activity = mActivity.get();
if(activity!=null){//由于弱引用当前Activity,验证当前Activity是否被回收,以避免异常出现

}
}
}
private final MyHandler mHandler = new MyHandler(this);

上一篇:nginx实现文件上传和下载


下一篇:DotNetBar for Windows Forms 12.2.0.7_冰河之刃重打包版原创发布-带官方示例程序版