Restore user in welcomeactivity resumeuser ()

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.