Android blog garden client (7) login function

Source: Internet
Author: User

Android blog garden client (7) login function
This is just a simple login function. operations that can be performed after successful logon have not yet been implemented. The principle of logon is to obtain Cookies and store data in the database. Using HttpClient to simulate logon has already been written in another blog, so I will not go into details here. The code is very simple: SplashActivity: Copy code 1 if (Personal. isLogin (this) {2 Config. FLAG_LOGIN = true; 3} 4 5 final Intent intent; 6 if (Config. FLAG_LOGIN) {7 intent = new Intent (SplashActivity. this, MainActivity. class); 8} else {9 intent = new Intent (SplashActivity. this, LoginActivity. class); 10} copy the code LoginActivity copy code 1 private void setListener () {2 OnClickListener listener = new OnClickListener () {3 4 @ Override 5 public void onClick (View v) {6 7 if (v. getId () = buttonLogin. getId () {8 userName = editTextUserName. getText (). toString (); 9 password = editTextPassword. getText (). toString (); 10 loginUrl = Config. LOGIN_RUL; 11 if (userName. trim (). equals ("") {12 13} else if (userName. trim (). equals ("") {14 15} else {16 login (); 17} 18} else if (v. getId () = buttonVisitor. getId () {19 Intent intent = New Intent (LoginActivity. this, 20 MainActivity. class); 21 startActivity (intent); 22 LoginActivity. this. finish (); 23} 24 25} 26}; 27 28 buttonLogin. setOnClickListener (listener); 29 buttonVisitor. setOnClickListener (listener); 30} 31 32 private void login () {33 LoginDialog dialog = new LoginDialog (this); 34 ProgressCallBack callBack = new ProgressCallBack () {35 36 @ Override37 public void action () {38 cookie = Personal. Login (userName, password, loginUrl); 39 if (cookie! = Null) {40 DBUtils. addCookie (LoginActivity. this, userName, cookie); 41 Intent intent = new Intent (LoginActivity. this, 42 MainActivity. class); 43 startActivity (intent); 44 LoginActivity. this. finish (); 45 Config. FLAG_LOGIN = true; 46} 47} 48}; 49 50 dialog. showProgressDialog ("login", "logging... ", callBack); 51 52}

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.