Android mobile platform-mobile SNS (2): Register and log on

Source: Internet
Author: User

Android registration and login implementation summary:

 

1. The registration interface and logon interface should provide mutual jumps,

 

2. During registration, all the information entered by the user at the beginning should be required. The content should be as simple as possible and not complex as possible. Other unnecessary information can be entered after the user registration is complete;

 

3. After the registration is complete, you can fill in other details by yourself. The entered items are preferably customized by the user, which makes the user more selective and flexible, not all user details are set to dead;

 

4. After successful registration, you can assign a default avatar to the user and choose whether to upload the Avatar;

 

5. Upload the Avatar function, that is, file upload, which can be uploaded asynchronously using the HTTP protocol;

 

6. login should also be as simple as possible. In order to make the user experience better, it is best to provide a password-remembering function;

 

7. When registering, first let the user register on the server. If the server fails to register, the system prompts that the registration failed. Otherwise, the user registers on the mobile database. If the mobile phone fails to register, the system also prompts that the registration fails. Otherwise, the system prompts that the registration is successful. This mechanism is used to cache user data locally and make the login faster;

 

8. During login, the user's identity is verified in the local database (SQLite). If the authentication fails, the authentication is performed on the server side. In this way, the authentication efficiency is higher.

 

9. After Successful Logon, you can save the login user information in a special class, so that the entire application can be accessed, removing a lot of tedious value transfer operations.

 

10. The following describes some key points for implementing the "Remember password" function:

 

(1) first, you need to select a storage method for storing the remembered password, in SQLite (database) or file format;

 

(2) Storage content: ID (self-increasing), user name, user password, and whether to remember (status ID, 0 indicates not remembered, 1 indicates remembering)

 

Why store the above fields? Let's take a look at the process. Multiple users have chosen to remember the password, and each user has successfully logged on. Then, they will change the status mark to 1. The next time they log on again, first, we need to remember who the last login user is. We can compare the logon time of each user, but this may be troublesome. Here I chose a self-increasing field ID, if ID is int, you only need to select the user whose ID is the largest and whose status ID is 1 and set the check box for remembering the password to true, and enter the username and password in the edit box (findmax_ SQL = "select * From login_user where id =" +
"(Select max (U. ID) from" +
"(Select * From login_user where State = '1') U" +
")";).

 

(3) After the user successfully logs on, the system determines whether to remember the password based on the user's choice, that is, to insert information into the database.

 

(4) logon is successful. There are four situations:

<1> remember that the password is true. If the entered username and password are not recorded in the database, add this record;

Addlogin_ SQL = "insert into login_user (username, password, state) values (?,?,?) ";

 

<2> remember that the password is true. If there is a record in the user name and password database, modify this record to 1;

Updatelogin_ SQL = "Update login_user set state =? Where username =? ";

 

<3> remember that the password is false. If there is a record in the user name and password database, modify this record, that is, remember that the status ID is changed to 0;

Updatelogin_ SQL = "Update login_user set state =? Where username =? ";

 

<4> In the last case, no operation is performed;

 

(5) Remember the password check box event and determine whether there are records in the database based on the entered username. If yes, remember to change the status ID to 1 if you remember that the password is true, and vice versa; if no, no operation is performed.

Findlogin_ SQL = "select * From login_user where username =? ";

 

(6) Listening to edittext

Private edittext usernamelogin;
Private edittext userpwdlogin;
 

Class edittextwatcher implements textwatcher {


@ Override
Public void aftertextchanged (editable arg0 ){
// Todo auto-generated method stub

}

@ Override
Public void beforetextchanged (charsequence S, int start, int count,
Int after ){
// Todo auto-generated method stub

}

@ Override
Public void ontextchanged (charsequence S, int start, int before, int count ){
// Todo auto-generated method stub
Map map = dbhelper. findlogin (S + "");
If (null! = Map ){
String Pwd = (string) map. Get ("password ");
String state = (string) map. Get ("state ");
If (null! = PWD & "1". Equals (State )){
Userpwdlogin. settext (PWD );
}
} Else {
Userpwdlogin. settext ("");
}
}
}

 

Edittextwatcher watcher = new edittextwatcher ();
Usernamelogin. addtextchangedlistener (watcher );

(7) On the startup interface, the information of the Last Logon user is displayed.

 

Db.exe csql
(

"Create Table" + usersqlutil. table_name_login +
"(" +
"Id integer primary key autoincrement, username text not null, Password text not null, state text" +
")"
);

 

 

Public map findlogin (string username ){
Cursor c = NULL;
String [] selectionargs = NULL;
String SQL = NULL;
Sqlitedatabase DB = This. getwritabledatabase ();

If (null! = Username ){
Log. I ("user", "findlogin ");
SQL = usersqlutil. findlogin_ SQL;
Selectionargs = new string [] {username };

} Else {
SQL = usersqlutil. findmax_ SQL;
// Selectionargs = new string [] {};
}

C = dB. rawquery (SQL, selectionargs );
Map map = NULL;
If (C. movetofirst ()){
Do {
Map = new hashmap ();
Map. Put ("username", C. getstring (1 ));
Map. Put ("password", C. getstring (2 ));
Map. Put ("State", C. getstring (3 ));
Log. I ("userinfo", C. getstring (1) + ":" + C. getstring (2) + ":" + C. getstring (3 ));
} While (C. movetonext ());
}
Return map;
}

 

 

 

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.