I. Code in welcomeactivity
Here we query users based on DeviceID.
// The network is used, so open a thread 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 ();}}};}
II. Resumeuser () method in the user class
/*** Resume user queries DeviceID * @ return user */public user resumeuser () {httputils HTTP = new httputils (); User Muser = NULL; Map <string, string> parammap = new hashmap <string, string> (); 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 ;}
3. The getexecute (MAP, string) method must be available in httputils.
For more information, see
Http://ipjmc.iteye.com/blog/1577495
/*** Is not static and cannot be referenced directly. * @ parammap, URL * @ throws ioexception * @ throws clientprotocolexception */Public String getexecute (Map <string, string> parammap, string URL) throws clientprotocolexception, ioexception {log. I ("getexecute", "in"); List <basicnamevaluepair> Params = new parameter list <basicnamevaluepair> (); For (map. entry <string, string> param: parammap. entryset () {string key = Param. getkey (); Params. add (New basicnamevaluepair (Key, Param. getvalue ();} // encode the logarithm string Param = urlencodedutils. format (Params, "UTF-8"); httpget = new httpget (URL + "? "+ PARAM); httpresponse response = client.exe cute (httpget); Return entityutils. tostring (response. getentity ()," UTF-8 ");}
Restore user in welcomeactivity resumeuser ()