//要用到网络 ,所以开一个线程
private void resumeUser() {
ToastUtils.ToastShort(this, "resume user");
new Thread(){
@Override
public void run() {
User mUser = new User();
mUser.setDeviceid(DeviceUtils.getDeviceId(WelcomeActivity.this));
User resumeUser = mUser.resumeUser();
if (resumeUser!=null){
WelcomeActivity.this.startActivity(new
Intent(WelcomeActivity.this, MainActivity.class));
WelcomeActivity.this.finish();
}
}
};
}
/**
* resume user 用的是查询deviceid
* @return User
*/
public User resumeUser() {
HttpUtils http = new HttpUtils();
User mUser = null;
MapparamMap= new HashMap();
paramMap.put("deviceid",getDeviceid() );
try{
String response = http.getExecute(paramMap, HttpGetUrl.getUser());
Log.i("User resumeUser() response",response);
mUser = new Gson().fromJson(response, User.class);
return mUser;
} catch (IOException e) {
e.printStackTrace();
}catch(Exception e2){
e2.printStackTrace();
}
return null;
}
/**
* 不是static,不能直接引用,
* @ paramMap, url
* @throws IOException
* @throws ClientProtocolException
*/
public String getExecute(MapparamMap, String url)
throws ClientProtocolException, IOException{
Log.i("getExecute" , "in");
List params = new LinkedList();
for (Map.Entry param: paramMap.entrySet()){
String key = param.getKey();
params.add(new BasicNameValuePair(key, param.getValue()));
}
//对对数编码
String param = URLEncodedUtils.format(params, "UTF-8");
HttpGet httpGet = new HttpGet(url+"?"+param);
HttpResponse response = client.execute(httpGet);
return EntityUtils.toString(response.getEntity(),"utf-8");
}