Android_ client Logic of landing

Source: Internet
Author: User

My personal website: www.shichengwu.com

Login instance Client processing logic: loginactivity

Package Com.amaker.wlo;import Android.app.activity;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.content.intent;import Android.content.sharedpreferences;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.Window; Import Android.widget.button;import Android.widget.edittext;import Com.amaker.util.httputil;import Com.amaker.util.loginencryption;public class Loginactivity extends Activity {/** * Login interface * @author SHICHENGWU *///DECLARE login button PR Ivate Button loginbtn;//declares user name, password input box private EditText useredittext,pwdedittext; @Overridepublic void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Endallactivity.getinstance (). addactivity (this);//For aesthetics, do not set the title requestwindowfeature (window.feature_no_title);// Set the current Activity interface layout Setcontentview (r.layout.activity_login);//Instantiate the component loginbtn = (Button) Findviewbyid by means of the Findviewbyid method ( R.id.login);//Instantiate a component Useredittext = (EditText) Findviewbyid (R.I) by means of the Findviewbyid methodD.useredittext);//Instantiate the component Pwdedittext = (EditText) Findviewbyid (R.id.pwdedittext) by means of the Findviewbyid method; Loginbtn.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {///Login if (Validate ()) {if (login ()) {Intent Intent = new Intent (loginactivity.this,mainmenuactivity.class); startactivity (Intent); Finish ();} Else{showdialog ("User name or password is wrong, please re-enter!")        "); }  }  }     });} Logon Method private Boolean login () {//Get user name string username = Useredittext.gettext (). toString ();//Get Password// MD5 compared to the database after encryption string pwd = Loginencryption.string2md5 (Pwdedittext.gettext (). toString ());//Get login result string result= Query (USERNAME,PWD), if (Result!=null&&result.equals ("0")) {return false;} Else{saveusermsg (result); return true;}}  Save user information to config file private void saveusermsg (String msg) {//user number string id = "";//user name String name = "";//Get information array string[] msgs = Msg.split (";"); int idx = msgs[0].indexof ("="); id = msgs[0].substring (idx+1); idx = msgs[1].indexof ("="); name = Msgs[1].substring (idx+1) ;//share information sharedpreferences pre = GetSHaredpreferences ("User_msg", mode_world_writeable); Sharedpreferences.editor Editor = Pre.edit (); Editor.putstring ("id", id); editor.putstring ("name", name); Editor.commit ();} Authentication Method Private Boolean validate () {String username = Useredittext.gettext (). toString (); if (Username.equals ("")) { ShowDialog ("User name is required!") "); return false;} String pwd = Pwdedittext.gettext (). toString (); if (Pwd.equals (")) {showDialog (" User password is required!) "); return false;} return true;} private void ShowDialog (String msg) {Alertdialog.builder Builder = new Alertdialog.builder (this); Builder.setmessage ( msg). Setcancelable (False). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {public V OID OnClick (dialoginterface dialog, int id) {}}); Alertdialog alert = Builder.create (); Alert.show ();} Querying private string query based on user name password (string username,string password) {//query parameter string queryString = "Username=" +username+ "& amp;password= "+password;//urlstring url = httputil.base_url+" Servlet/loginservlet? " +querystring;//query Returns the result return Httputil.querystringforpost (URL); }}


In this case, you may not understand the client and server interactions, the next one will talk about the JDBC model involved and the server processing logic of the login instance.

Android_ client Logic of landing

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.