Android automatically logs on after remembering the password. android remembers the password.

Source: Internet
Author: User

Android automatically logs on after remembering the password. android remembers the password.

/**
*
* @ Author alex
* @ Version 5:25:45
*
*/
Public class LoginActivity extends Activity {
Private EditText name;
Private EditText pass;
Private CheckBox isRemenber;
Private CheckBox isLoginSelf;
Private Button longin;
Private ProgressDialog mDialog;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Name = (EditText) findViewById (R. id. et_name );
Pass = (EditText) findViewById (R. id. et_pass );
IsRemenber = (CheckBox) findViewById (R. id. isremenber );
IsLoginSelf = (CheckBox) findViewById (R. id. isloginself );
Longin = (Button) findViewById (R. id. longin );

Final SharedPreferences pre = getSharedPreferences ("longinvalue", MODE_WORLD_WRITEABLE );
If (pre! = Null ){
// Remember the password
If (pre. getBoolean ("isrmb", false) = true ){
Name. setText (pre. getString ("name", null ));
Pass. setText (pre. getString ("pass", null ));
IsRemenber. setChecked (true );
}
If (pre. getBoolean ("islgs", false) = true ){
IsLoginSelf. setChecked (true );
CreatDialog ();
New Thread (){
Public void run (){
Try {


Thread. sleep (3000 );
If (mDialog. isShowing ()){
MDialog. dismiss ();
}
Intent intent2 = new Intent (LoginActivity. this, Show. class );
StartActivity (intent2 );
} Catch (Exception e ){
// TODO: handle exception
}
}
}. Start ();
}
}
IsRemenber. setOnCheckedChangeListener (new OnCheckedChangeListener (){

@ Override
Public void onCheckedChanged (CompoundButton buttonView, boolean isChecked ){
// TODO Auto-generated method stub
If (isRemenber. isChecked () = false ){
IsLoginSelf. setChecked (false );
}
}
});
IsLoginSelf. setOnCheckedChangeListener (new OnCheckedChangeListener (){

@ Override
Public void onCheckedChanged (CompoundButton buttonView, boolean isChecked ){
// TODO Auto-generated method stub
IsRemenber. setChecked (true );
}
});
Longin. setOnClickListener (new OnClickListener (){

@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
If (! Name. getText (). toString (). equals ("")&&! Pass. getText (). toString (). equals ("")){
If (isLoginSelf. isChecked ()){
Pre. edit (). putBoolean ("isrmb", true). putBoolean ("islgs", true). putString ("name", name. getText (). toString ())
. PutString ("pass", pass. getText (). toString (). commit ();
} Else {
If (isRemenber. isChecked ()){
Pre. edit (). putBoolean ("isrmb", true). putBoolean ("islgs", false). putString ("name", name. getText (). toString ())
. PutString ("pass", pass. getText (). toString (). commit ();
} Else {
Pre. edit (). putBoolean ("isrmb", false). putBoolean ("islgs", false). putString ("name", name. getText (). toString ())
. PutString ("pass", pass. getText (). toString (). commit ();
}
}
Intent intent = new Intent (LoginActivity. this, Show. class );
StartActivity (intent );
} Else {
Toast. makeText (getApplicationContext (), "the password or account cannot be blank! ", Toast. LENGTH_LONG). show ();
}


}
});
}
Private void creatDialog (){
MDialog = new ProgressDialog (this );
MDialog. setTitle ("verifying ");
MDialog. setMessage ("logging in... please wait ");
MDialog. setIndeterminate (true );
MDialog. setCancelable (true );
MDialog. show ();

}
}

Import android. app. Activity;
Import android. OS. Bundle;


Public class Show extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
SetContentView (R. layout. show );
}
}

<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "alex.sias.com"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">


<Uses-sdk android: minSdkVersion = "8"/>


<Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE">
</Uses-permission>


<Application
Android: icon = "@ drawable/icon"
Android: label = "@ string/app_name"
Android: theme = "@ android: style/Theme. NoTitleBar. Fullscreen">
<Activity
Android: name = ". LoginActivity"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>


<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
<Activity android: name = "Show">
</Activity>
</Application>


</Manifest>

Two layout files are used.

<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "@ drawable/chat_bg_default"
>
<TextView
Android: layout_height = "50dp"
Android: layout_width = "fill_parent"
Android: gravity = "center"
Android: textSize = "24sp"
Android: text = "Logon interface"
Android: textColor = "@ color/white"
Android: background = "@ drawable/song_index_item_bg"/>
<ImageView
Android: id = "@ + id/iv"
Android: layout_height = "220dp"
Android: layout_width = "230dp"
Android: layout_marginTop = "110dp"
Android: src = "@ drawable/background"
Android: layout_centerHorizontal = "true"
Android: scaleType = "fitXY"/>
<TextView
Android: id = "@ + id/TV _name"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: textSize = "15sp"
Android: layout_marginTop = "7dp"
Android: text = "account :"
Android: layout_alignLeft = "@ + id/iv"
Android: layout_alignTop = "@ + id/iv"
Android: layout_marginLeft = "7dp"
Android: textColor = "@ color/green"/>
<EditText
Android: id = "@ + id/et_name"
Android: layout_height = "25dp"
Android: layout_width = "210dp"
Android: layout_marginTop = "7dp"
Android: layout_below = "@ + id/TV _name"
Android: background = "@ drawable/shape"
Android: layout_alignLeft = "@ + id/TV _name"/>
<TextView
Android: id = "@ + id/TV _pass"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: textSize = "15sp"
Android: text = "Password :"
Android: layout_alignLeft = "@ + id/TV _name"
Android: layout_below = "@ + id/et_name"
Android: layout_marginTop = "7dp"
Android: textColor = "@ color/green"/>
<EditText
Android: id = "@ + id/et_pass"
Android: layout_height = "25dp"
Android: layout_width = "210dp"
Android: background = "@ drawable/shape"
Android: layout_marginTop = "7dp"
Android: layout_below = "@ + id/TV _pass"
Android: layout_alignLeft = "@ + id/TV _name"/>
<CheckBox
Android: id = "@ + id/isremenber"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: layout_alignLeft = "@ + id/TV _name"
Android: layout_marginTop = "10dp"
Android: text = "Remember password"
Android: textSize = "11sp"
Android: textColor = "@ color/huise"
Android: layout_below = "@ + id/et_pass"
Android: button = "@ drawable/mycheckbox"/>
<CheckBox
Android: id = "@ + id/isloginself"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: layout_alignRight = "@ + id/et_name"
Android: layout_marginTop = "10dp"
Android: text = "Automatic Logon"
Android: textSize = "11sp"
Android: textColor = "@ color/huise"
Android: layout_below = "@ + id/et_pass"
Android: button = "@ drawable/mycheckbox"/>
<Button
Android: id = "@ + id/longin"
Android: layout_height = "25dp"
Android: layout_width = "210dp"
Android: layout_below = "@ + id/isloginself"
Android: layout_alignLeft = "@ + id/et_pass"
Android: layout_marginTop = "10dp"
Android: text = "login"
Android: gravity = "center"
Android: background = "@ drawable/loginbtn"/>
</RelativeLayout>

<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "@ color/white">
<TextView
Android: layout_height = "fill_parent"
Android: layout_width = "fill_parent"
Android: text = "! "
Android: textSize = "40sp"
Android: gravity = "center"/>

</LinearLayout>


Android ---- imitate QQ login Remember password and automatic login how to write ?? Urgent

Remember the password and save it to the local database SQLite. When automatic logon is triggered, the system obtains the ID and password data you want to log on to from the local database table every time you start the program, to match the connection server .. There should be two (or one) Flag values at the beginning of the program. One is the flag that triggers the password record, and the other is the sign of automatic login, which is written into the database record, read these two values each time you start the program. If they are true, perform the preceding operations.
 
On the Android tablet, how does qq hd remove the default Remember password and automatic login?

Click QQ on the desktop to go To the logon page. Remember the password and check the automatic logon information. I hope it will help you.

After logging in, you can log out.
 

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.