Messy code 1

Source: Internet
Author: User

Public interface callback {public void onsucc (); Public void onfail (string MSG );}

////////////////////////

@ Override public void onclick (view v ){

This. getserverappversion (New callback (){

@ Override public void onsucc (){

New alertdialog. Builder (moreversionactivity. This). settitle ("version update detection"). setmessage ("the new version is detected. Do you want to download the update? "). Setpositivebutton ("yes", new dialoginterface. onclicklistener () {@ override public void onclick (dialoginterface dialog, int which) {moreversionactivity. this. downloadapp ();}}). setnegativebutton ("no", null ). setcancelable (false ). show ();

}

@ Override public void onfail (string MSG) {// log. E ("findeventaddactivity", MSG );}

});

}

 

Public String getserverappversion (final callback ){

Requestparams Params = new requestparams ();

Communicationtools. communication (Const. get_server_app_version_path, Params, new jsonhttpresponsehandler () {@ override public void onsuccess (jsonobject data) {// whether data is uploaded successfully try {string serverversion = data. getstring ("versionno ");

String currentvsersion = moreversionactivity. This. getversion ();

If (serverversion! = NULL & serverversion. Contains ("S") {serverversion = serverversion. Replace ("S ","");}

If (! Serverversion. Equals (currentvsersion) {callback. onsucc ();} else {publicmethods. showtoasttopshort (getapplicationcontext (), "it is already the latest version! ") ;}} Catch (jsonexception e) {publicmethods. showtoasttopshort (getapplicationcontext ()," network connection failed! "); E. printstacktrace ();}

}

@ Override public void onfailure (throwable arg0) {publicmethods. showtoasttopshort (getapplicationcontext (), "network connection failed! "); Callback. onfail (" server connection failed ");}});

Return NULL ;}

 

//////////////////////////////////////// ///////////

 

New thread (New runnable () {@ override public void run () {logoff. prepare (); try {URL url = new URL (Const. get_server_app_download_path); httpurlconnection urlconn = (httpurlconnection) URL. openconnection (); urlconn. setrequestproperty ("Accept-encoding", "Identity"); urlconn. connect (); urlconn. setconnecttimeout (60*1000); inputstream is = urlconn. getinputstream (); message MSG = handler. obtainmescript E (0); MSG. OBJ = urlconn. getcontentlength (); MSG. sendtotarget (); downfile (is);} catch (exception e) {e. printstacktrace (); // publicmethods. showtoasttopshort (getapplicationcontext (), // "Download failed! "); New alertdialog. Builder (moreversionactivity. This). settitle (" prompt "). setmessage (" Download failed. Please check whether the network is normal and try again later! "). Setpositivebutton (" OK ", null). setcancelable (false). Show ();} Looper. Loop ();

}). Start ();

Messy code 1

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.