Android Login Registration Screen with SQLite Database Example
Android Login Registration Screen with SQLite Database Example
Here we will learn complete details about Android Login Registration Screen with SQLite Database Example. Also discuss about how to create or design Android Login (Sign In) and New Registration (Sign Up) screen. We will learn how to save application’s data in it’s own Android SQlite Database. You can also download complete source code for Android Login Registration Screen with SQLite Database Example.
To make the example very simple. In this example we will create one home screen activity, in which we will use 2 buttons (one is used for ‘Sign In’ option and other is for ‘Sign Up’ option). Then we will show Login and ‘New Registration’ screen on the onClick option of the respective buttons. All required Login and Registration user-data will be save in application’s own Android SQLite database. The database will be stored in the application’s context, so that no other android applications will access the data.
Steps Required to Create Android Login Registration Application
1. Create a Home Screen Activity , Which will hold ‘Sign In‘ and ‘Sign Up‘ options.
2. Create layouts for home screen and ‘Sign In‘ and ‘Sign Up‘ Screens.
4. Create a SQLite Database in the application’s context, so that we can save all required user data (‘Sign In‘ and ‘Sign Up‘ details).
5. Code Logic in Application’s Java files.
6. Run Android Login Registration app on Device/Emulator.
7. Download complete android example for this project.
Android Layouts for Login Registration Application
1. Default layout (main.xml)
This is used for home screen in this application, which holds 2 buttons for Sign In and Sign Up options.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_vertical" > <Button android:id="@+id/buttonSignIN" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Sign In" android:onClick="signIn"/> <Button android:id="@+id/buttonSignUP" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Sign Up" /> </LinearLayout> |
2. login.xml
This xml is used for Log In (Sign In) screen in this application.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editTextUserNameToLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User Name" android:ems="10" > <requestFocus /> </EditText> <EditText android:id="@+id/editTextPasswordToLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" android:hint="Password" /> <Button android:id="@+id/buttonSignIn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Sign In" /> </LinearLayout> |
3. signup.xml
This xml is used for first time user, so for new registration we will use this xml file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_vertical" > <EditText android:id="@+id/editTextUserName" android:hint="User Name" android:layout_width="match_parent" android:layout_height="wrap_content" > <requestFocus /> </EditText> <EditText android:id="@+id/editTextPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Password" android:inputType="textPassword" /> <EditText android:id="@+id/editTextConfirmPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Confirm Password" android:inputType="textPassword" /> <Button android:id="@+id/buttonCreateAccount" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Create Account" android:layout_marginBottom="60dp" /> </LinearLayout> |
Now Coming to Java Codes
We have used 4 Java files in this application. You can also find complete source code description inside the code, once you download complete code from here.
1. HomeActivity.java
In this file we have implemented logic for onClick button function, which is used for ‘Sign In’ and ‘Sign Up’ options. Also we will just create a reference to the instance of SQLite Database for storing and querying data in the database.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
package com.techblogon.loginexample; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class HomeActivity extends Activity { Button btnSignIn,btnSignUp; LoginDataBaseAdapter loginDataBaseAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // create a instance of SQLite Database loginDataBaseAdapter=new LoginDataBaseAdapter(this); loginDataBaseAdapter=loginDataBaseAdapter.open(); // Get The Refference Of Buttons btnSignIn=(Button)findViewById(R.id.buttonSignIN); btnSignUp=(Button)findViewById(R.id.buttonSignUP); // Set OnClick Listener on SignUp button btnSignUp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub /// Create Intent for SignUpActivity abd Start The Activity Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class); startActivity(intentSignUP); } }); } // Methos to handleClick Event of Sign In Button public void signIn(View V) { final Dialog dialog = new Dialog(HomeActivity.this); dialog.setContentView(R.layout.login); dialog.setTitle("Login"); // get the Refferences of views final EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin); final EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin); Button btnSignIn=(Button)dialog.findViewById(R.id.buttonSignIn); // Set On ClickListener btnSignIn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // get The User name and Password String userName=editTextUserName.getText().toString(); String password=editTextPassword.getText().toString(); // fetch the Password form database for respective user name String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName); // check if the Stored password matches with Password entered by user if(password.equals(storedPassword)) { Toast.makeText(HomeActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show(); dialog.dismiss(); } else { Toast.makeText(HomeActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show(); } } }); dialog.show(); } @Override protected void onDestroy() { super.onDestroy(); // Close The Database loginDataBaseAdapter.close(); } } |
2. SignUPActivity.Java
Here we will have complete logic, after we will click ‘Sign Up’ option from main screen.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
package com.techblogon.loginexample; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SignUPActivity extends Activity { EditText editTextUserName,editTextPassword,editTextConfirmPassword; Button btnCreateAccount; LoginDataBaseAdapter loginDataBaseAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.signup); // get Instance of Database Adapter loginDataBaseAdapter=new LoginDataBaseAdapter(this); loginDataBaseAdapter=loginDataBaseAdapter.open(); // Get Refferences of Views editTextUserName=(EditText)findViewById(R.id.editTextUserName); editTextPassword=(EditText)findViewById(R.id.editTextPassword); editTextConfirmPassword=(EditText)findViewById(R.id.editTextConfirmPassword); btnCreateAccount=(Button)findViewById(R.id.buttonCreateAccount); btnCreateAccount.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String userName=editTextUserName.getText().toString(); String password=editTextPassword.getText().toString(); String confirmPassword=editTextConfirmPassword.getText().toString(); // check if any of the fields are vaccant if(userName.equals("")||password.equals("")||confirmPassword.equals("")) { Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show(); return; } // check if both password matches if(!password.equals(confirmPassword)) { Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show(); return; } else { // Save the Data in Database loginDataBaseAdapter.insertEntry(userName, password); Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show(); } } }); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); loginDataBaseAdapter.close(); } } |
3. DataBaseHelper.Java
This file will be use to create a new DB, when no database exists in disk and the helper class will do the needful for us. Also this class will be help us to upgrade the version of the DB if required.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package com.techblogon.loginexample; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper { public DataBaseHelper(Context context, String name,CursorFactory factory, int version) { super(context, name, factory, version); } // Called when no database exists in disk and the helper class needs // to create a new one. @Override public void onCreate(SQLiteDatabase _db) { _db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE); } // Called when there is a database version mismatch meaning that the version // of the database on disk needs to be upgraded to the current version. @Override public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) { // Log the version upgrade. Log.w("TaskDBAdapter", "Upgrading from version " +_oldVersion + " to " +_newVersion + ", which will destroy all old data"); // Upgrade the existing database to conform to the new version. Multiple // previous versions can be handled by comparing _oldVersion and _newVersion // values. // The simplest case is to drop the old table and create a new one. _db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE"); // Create a new one. onCreate(_db); } } |
4. LoginDataBaseAdapter.Java
This file is required to handle all Database operations like (create DB, Insert record, update record, Delete record, Close DB, and Cursor related stuffs.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
package com.techblogon.loginexample; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; public class LoginDataBaseAdapter { static final String DATABASE_NAME = "login.db"; static final int DATABASE_VERSION = 1; public static final int NAME_COLUMN = 1; // TODO: Create public field for each column in your table. // SQL Statement to create a new database. static final String DATABASE_CREATE = "create table "+"LOGIN"+ "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME text,PASSWORD text); "; // Variable to hold the database instance public SQLiteDatabase db; // Context of the application using the database. private final Context context; // Database open/upgrade helper private DataBaseHelper dbHelper; public LoginDataBaseAdapter(Context _context) { context = _context; dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION); } public LoginDataBaseAdapter open() throws SQLException { db = dbHelper.getWritableDatabase(); return this; } public void close() { db.close(); } public SQLiteDatabase getDatabaseInstance() { return db; } public void insertEntry(String userName,String password) { ContentValues newValues = new ContentValues(); // Assign values for each row. newValues.put("USERNAME", userName); newValues.put("PASSWORD",password); // Insert the row into your table db.insert("LOGIN", null, newValues); ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); } public int deleteEntry(String UserName) { //String id=String.valueOf(ID); String where="USERNAME=?"; int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ; // Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show(); return numberOFEntriesDeleted; } public String getSinlgeEntry(String userName) { Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null); if(cursor.getCount()<1) // UserName Not Exist { cursor.close(); return "NOT EXIST"; } cursor.moveToFirst(); String password= cursor.getString(cursor.getColumnIndex("PASSWORD")); cursor.close(); return password; } public void updateEntry(String userName,String password) { // Define the updated row content. ContentValues updatedValues = new ContentValues(); // Assign values for each row. updatedValues.put("USERNAME", userName); updatedValues.put("PASSWORD",password); String where="USERNAME = ?"; db.update("LOGIN",updatedValues, where, new String[]{userName}); } } |
Note: for Log In Dialog Screen, we just used the login.xml with the below code snippet. You can find below code snippet in HomeActivity.java file.
|
1 2 3 |
final Dialog dialog = new Dialog(HomeActivity.this); dialog.setContentView(R.layout.login); dialog.setTitle("Login"); |
Finally Applications Manifest File
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.techblogon.loginexample" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.techblogon.loginexample.HomeActivity" 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=".SignUPActivity"/> </application> </manifest> |
How to Build and Run the Sample on Android Device
You can download the sample form below link and build the application and run it on device/emulator. Also you can copy paste the code in ti your project.
After Run the application and save any user data, you can see login.db file that has been generated and saved for your application.
Download Example
Download Example with Source Code for ‘Android Login Registration Screen with SQLite Database Example’ from here.
If you want to learn about ListView with SQLite Database Connection Using Adapter in Android then click here.
I hope this small tutorial will help you at it’s best.
1. You might like to learn how to save persistent user data using Android SharedPreference with Example.
2. You might like to learn ListView with SQLite Database Connection in Android.










Previous Page
Android Tutorial Home Page










I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon". Techblogon is a technology blog. We regularly update this blog with really nice and helpful tips n tricks, latest updates on new technologies. I am also an active contributor for the blog-"Gadgets and Gizmos World".
Job is my necessity, but blogging is my passion.
Connect with me on
Very useful post. I am looking for this simple post long time ago
how to check whether the data has been stored in database or not?
Dear Meghali,
There are varieties of ways to check the stored data. Lets have discuss on Login Example.
If you are running the app on device/emulator, then connect your device/emulator to your PC.
Then start Eclipse->DDMS. Then select the connected device/emulator from left side pannel.
Then goto ‘File Explorer’. then goto ‘data/data/com.techblogon.loginexample/database/login.db’. This file will be in your device and ‘com.techblogon.loginexample’ is the package name.
Then pull the file and check it using SQLite Browser. I have attached the image below the post. pls see above.
The best way:Also you can check all SQLite helper class function with try/catch block, if your data has been stored, then no exception will occurred.
@Meghali: you can check the database contents from DDMS perpective in Eclipse. DDMs–>file explorer->data->name of your project–>databases–
Brilliant tutorial…Is it a good practice or will there be a problem if we call the signup activity from the main thread although we use intents?
Btw,it would be great if you could post a tutorial on sending the sql data to remote server as JSON or XML data through a Rest webservice
Dear Vyshakh,
You can also call the signup activity from the main thread. No issue, but if you need to get some result back then pls use startActivityForResult(Intent, int).
I will update the tutorial on sending the sql data to remote server as JSON or XML data through a Rest webservice very soon.
br
techblogon
thank you so much
its telling R cannot resolve in HomeActivity
Dear ikhlas,
You can go through my article ‘Some Common Android Development Errors and Solutions’. that might help you.
Link: http://techblogon.com/common-android-development-errors-solutions/
However i have build the code using SDK version Android 4.0.3. your version might be different. so change the version.
Also you can check the proper xml file names if you just copy the code snippet.
Did you download the code? or copy paste from the code snippet?
It is better to create a new project with given project and package name, then replace the content.
br
techblogon.
Its ok now thANK you….
Now i these error have pop up in….SignUPActivity.java
editTextUserName=(EditText)findViewById(R.id.editTextUserName);
editTextPassword=(EditText)findViewById(R.id.editTextPassword);
editTextConfirmPassword=(EditText)findViewById(R.id.editTextConfirmPassword);
btnCreateAccount=(Button)findViewById(R.id.buttonCreateAccount);
//////////////
editTextUserName
editTextPassword
editTextUserName cannot be resolved or is not a field
buttonCreateAccountcannot be resolved or is not a field
buttonCreateAccount
Thank you in advance
Dear ikhlas,
You might forget to add these lines in the java file “SignUPActivity.Java” as in the above code.
It may help you.
EditText editTextUserName,editTextPassword,editTextConfirmPassword;
Button btnCreateAccount;
editTextUserName=(EditText)findViewById(R.id.editTextUserName);
editTextPassword=(EditText)findViewById(R.id.editTextPassword);
editTextConfirmPassword=(EditText)findViewById(R.id.editTextConfirmPassword);
Now its i got problem with id…
Can i also i have tutorial for splash screen please..
THank you so much
nOWS ITS TELLING ME cANNOT solve ID,Layout,,
Which sdk version is showing for your project?
pleas send the exact error logs, so that i can say some solution.
API 17 version4.2.2
change the SDK version as your,s. goto project and right click on it, then property. then choose SDK version. it might help you.
But i suggest, make a new project and copy code to your project file. make sure all the packages are added in the project
I got it bro thank you very much.Now it is working fine. all records got inserted.
can u tell how to create auto login using shared preferences .I mean if we check the check box while login by the next time when we open the app it has to redirect to home page.
Dear Jeelan,
It is very simple. When user check the check box for auto login, save the checkbox state in a shared pref. When user open the app next time, first read the state of the checkbox in your homepage(login page)’s oncreate() method before showing the GUI, destroy the login page and then start the required activity directly.
If you are new to android shared pref, then let me know, i will update an article with example for android shared preference
Thank u very much for reply I am new to android could you plz update the code of shared preferences and one more thing is how to retrive feilds from database.
Ok I will update sharedpref very soon.
However for retrive feilds from database, you might like my article with example.Here in the code we retrieve username from the database
Link: http://techblogon.com/android-login-registration-screen-with-sqlite-database-example/
Sqlite database was fantabilous.Is it possible to retive the values in one method {getsingleentry()} .
Just modifiy the loginpage page using sharedpref so that it will redirect main page.
delete the R.java file , clean project and rebuild.
you can check the xml file name. make sure you don’t have any space in the file name.
this is nice post…
But, can you help me about login in android with pattern code??
Thanks… ^_^
Nice code and i really thankful to you for helping me though you code…..
very nice …….so simple and easy to understand
thank you…
Sir i am going to develop screen lock…..
can u help ……??
how to bring my login activity on screen when user press unlock button?
pleas…
thank u…
Thanks for the article. I am facing small problem with the code and wondering if you can help. The app runs fine on my phone but it does not create the database file. basically under Data there is nothing. Would you know what might cause it. I set android.debuggable=”true” in android manifest and put a break point at static final String DATABASE_CREATE but it does not even trigger when I create new account. Thanks for your help
You can try by changing the database name in the code.
Check if it works for you.
br
techblogon
Sir how if i will add form change password?
For change password, you can put an option menu or button, start a new activity, then get user input(like current, new, confirm password). search the new password it in database, then update it, the update function has already written in the code.
good tuto
This is login page :Launcher Activity
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity
{
protected static final Bundle edt = null;
Button btnSignIn1,btnSignUp;
LoginDataBaseAdapter loginDataBaseAdapter;
CheckBox ch=null;
SharedPreferences pre;
public static String filename=”Myfile”;
//public static final String PREF_NAME=”store”;
/*public static final String PREFS_NAME = “MyPrefsFile”;
public static final String PREF_PWD = “MyPrefsFile”;
private static final String PREF_USERNAME = “userName”;
private static final String PREF_PASSWORD = “password”;
String PROPERTY_CONTENT_TYPE = “Content-Type”;*/
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
pre=getSharedPreferences(filename,0);
/* SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE);
final String userName = pref.getString(PREF_USERNAME, null);
SharedPreferences pref1 = getSharedPreferences(PREF_PWD,MODE_PRIVATE);
final String password = pref1.getString(PREF_PASSWORD, null); */
ch=(CheckBox)findViewById(R.id.checkBox1);
/* if(ch.isChecked()){
SharedPreferences settings=getSharedPreferences(“PREF_NAME”,0);
if(settings.getString(“log”,”").toString().equals(“log”));
Intent intent = new Intent(Login.this, MainMenu.class);
startActivity(intent);
}*/
// create a instance of SQLite Database
loginDataBaseAdapter=new LoginDataBaseAdapter(this);
loginDataBaseAdapter=loginDataBaseAdapter.open();
// Get The Refference Of Buttons
btnSignIn1=(Button)findViewById(R.id.buttonSignIn);
btnSignUp=(Button)findViewById(R.id.buttonSignUP);
// Set OnClick Listener on SignUp button
btnSignUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
/// Create Intent for SignUpActivity and Start The Activity
Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class);
startActivity(intentSignUP);
}
});
// Methos to handleClick Event of Sign In Button
//public void signIn(View V)
// {
//final Dialog dialog = new Dialog(Login.this);
//dialog.setContentView(R.layout.login);
//dialog.setTitle(“Login”);
// get the Refferences of views
/* final EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);
final EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin);
*/
Button btnSignIn1=(Button) findViewById(R.id.buttonSignIn);
// Set On ClickListener
btnSignIn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// get The User name and Password
final EditText editTextUserName=(EditText) findViewById(R.id.editTextUserNameToLogin);
final EditText editTextPassword=(EditText) findViewById(R.id.editTextPasswordToLogin);
String userName=editTextUserName.getText().toString();
String password=editTextPassword.getText().toString();
// fetch the Password form database for respective user name
String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);
// check if the Stored password matches with Password entered by user
/*if(ch.isChecked())
{
SharedPreferences.Editor edt=pre.edit();
edt.putString(“sharedata1″,userName);
edt.putString(“sharedata2″,password);
edt.commit();
}*/
/*if(ch.isChecked()){
if(edt.getString(“sharedata1″,”").toString().equals(“userName”) && edt.getString(“sharedata2″,”").toString().equals(“passowrd”));
{
Intent intent = new Intent(Login.this, MainMenu.class);
startActivity(intent);
}*/
/*getSharedPreferences(PREFS_NAME,MODE_PRIVATE)
.edit()
.putString(PREF_USERNAME, editTextUserName.getText().toString())
.putString(PREF_PASSWORD, editTextPassword.getText().toString())
.commit(); */
if(password.equals(storedPassword))
{
Intent in=new Intent(getApplicationContext(),MainMenu.class);
startActivity(in);
finish();
if(ch.isChecked())
{
SharedPreferences.Editor edt=pre.edit();
edt.putString(“sharedata1″,userName);
edt.putString(“sharedata2″,password);
edt.commit();
/*Intent in1=new Intent(getApplicationContext(),MainMenu.class);
startActivity(in1);
finish();*/
}
/*Toast.makeText(HomeActivity.this, “Congrats: Login Successfull”, Toast.LENGTH_LONG).show();
dialog.dismiss();*/
}
else
{
Toast.makeText(Login.this, “User Name or Password does not match”, Toast.LENGTH_LONG).show();
}
}
});
}
/*
dialog.show();
}*/
@Override
protected void onDestroy() {
super.onDestroy();
// Close The Database
loginDataBaseAdapter.close();
}
}
one more thing i was trying to make autologin using shared preferences but it is not redirecting to main menu when activty starts
Can u please help me.
Read the auto login state from the main page’s onCreate() function before showing your GUI, if it is true, then start your required activity and destroy the current activity.
Sir i run this code but i have got exception Unfortunately dbfile has stopped.
how can solve this ……….
hello man, its a great post. but when i click on the button of the create account everything is successfull but it doesnt take me to the main page.how to do it. thx
It is very simple, destroy the current activity and start the main page activity.
Let me know if you are not clear
hello man , i need more help. i want to improve this login and add a type(administrator and user).thx man
sir i am finding the error in login.xml & sifnup.xml
thet net beans says error parsing xml
so i want the solution of this error in netbeans ide
where i hav to locate this 2 xml file ????
Make sure the xml file name should not contain any space between.
hi…its finally working
Can you please tell me how can i go to another page after login succesfully instead of HOMEactivity…please
and also if i want to create a new registration form how should i do it…
thx
It is simple. For showing another page, just start a new activity.
I HAVE ALREADY created a new activity,,,
After login succesfully i want it to the new activity,,,,
i have everything but it telling Application stop …..
i have replace in the login page…where toast congrats login succesfully..
i replase with the new activity still the same…
Sir i am using ur code for ths login app on device but it is not showing database values and even not picking up values stored in database.it is showing the toast message username or password did not match.please suggest
Dear Gaurav,
First you need to add user name and password, store it, then login
Hi Smruthi Ranjan
can you please help me in connecting SQLite database, here Iam using your SQLiteStorageOption project, its running in emulater but problem is it is not showing any data and if i try add option throwing some error.
pls tell me the exact error, then only i can help you. did you use my example for it?
Sir, I m having a error of com.Linprog.LoginDatabaseAdapter.insertEntry(LoginDatabaseAdapter.java:53)
plz help me to solve it out.
pls update the complete error. then i will try to help you
I want to make a project using Android
Helps users to chat and communicate with each other
Can you help me so
Thank you
could u please update the auto login page using check box (shared preferences).
i have gone through shared preferences tutorials.But am unable to make my requirement.
What is your requirement for sharedpreferences?
in the login page if we check the check box (Remember me) by the next time it has to redirect to main menu.
sir how can we read database table in this project
You just need to execute SQL queries.
how to hosting an android project please help me
Thank you
sir how can we connect the android apps with external database
Hi man….. I want to create a gps based vehicle tracker software needed…. please send me the code to me
i got an error for as follow :
string password = password.getText().toString();
it said that i have an error at the getText() baecause it is undefined to string. can u help me?
make ‘S’ capital (String) instead of string.
Great Tutorial
my emulator shows LoginDataBaseAdapter cannot resilved to a type……….wii u plz help me
import the corresponding package in your code
what if i want to check if username already exists in my MYSQL database??
what if i want to check if username already exists in my MYSQL database??And i also want my password to be of atleast 6 characters.
help me guys…..
if you want to check existing user name, then query the input user name. API function is already written in the code.
If yo want to check for at least 6 chars, then it is very simple. Just add a check in your code like [if(6>count){} x)] by counting the input characters before save it into the database
i want to prevent insertion of entries if username and password are already inserted in database. I tried to query that but no luck..Any help??
Thanks for such a wonderful article. I have a question here. Is the database (that we have created) local to the device where the app is installed? On my registration page I am collecting the user info the very first time the app is installed and I need to store it somewhere just to keep a track of the users. There is no login page or I would say no login is required to use the app (just one time registration during installation). If the SQLite db instance that we are creating above is local to the device that i won’t be able to access the list of users.
I hope you got my question. Please let me know if you need futher info.
creating Service in Android is very easy, I am getting so many request to update android service example.
I will update the same in my blog asap.
Thanx a lot. waiting for ur help