Sample Android Login Application

After developing wide range of Java applications including Web and Desktop based since about four and half years now I have started learning Android Since last one month and day by day I'm getting very keen in learning the Same.

Following is the Sample Android Login Application which I have developed and would like to share with everyone.
This Application is at its very basic stage, Irrespective of the database used.

It works as follows:
If User Name and Password Entered are similar it gives a Toast pop up saying that "Login Successful"
Else It will give a Toast pop up Saying that "Invalid Login"

I feel it will help the Android learning beginners:

This application is developed on Following platforms:
Ubuntu 10.10,
Eclipse 3.5 Galileo
Android 2.1 SDK

Following is the Screen short of the Application:

Following is the Screen short of the Application:

I have used Table Layout, Following is the Layout Code for the Same:

<TableLayout xmlns:android=""
android:text="User Name: " 


android:text="Password: " 






Following is the Activity Code for the Application:

package com.mayuri.login;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SampleLogin extends Activity {

EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        btnLogin.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

        Toast.makeText(SampleLogin.this, "Login Successful",Toast.LENGTH_LONG).show();
       } else{
        Toast.makeText(SampleLogin.this, "Invalid Login",Toast.LENGTH_LONG).show();


Following are the Screenshots of the Applications, Depending on their behaviours i.e. "Login Success" and "Invalid Login".

I hope this example proves to be useful to the people learning Android.
I will keep on updating with more and more examples.


Best Car pool Android Application Best Car Pool Application Source Code Download Here

Best Social Network Cordova Ionic Application Best Social Networking Source Code Cordova Ioinc Application Download Here

Best Android Application, Android Restaurant System Best Android Restaurant Application Source code download here

Best Android Application Android Chat Source code download Android Chat Source code download

Best Android Quiz Source Code Download Best Android Quiz Source Code Download here

More and Lots of useful Android source codes here Best Android Source codes download here


akhtar said…
Good work ...thank you
can you please show how to start the sub_activity from the same activity by using intents????
Mayuri Ruparel said…
Thanks Akhtar!

Try this:

Intent myIntent = new Intent(view.getContext(), ActivityClassName.class);
startActivityForResult(myIntent, 0);
Nazim said…
Its a Mind blowing work for android developers. mayuri mam is my guru.
thanks a lot mam.
satyam said…
Thanks I am finding this type of login form ..

With use of database how datafetch??
satyam said…
thaks I am looking for this type of loginform

Hello ,can you please find how to fetch data form databse...

using of webservices...
Valmik Pujara said…
This comment has been removed by the author.
Valmik Pujara said…
This comment has been removed by the author.
Valmik Pujara said…
I just want to knw that how to check whether the edittext is focused or not can u plz tell me which method i should use

i tried isFocused() and hasFocus() but dint work.....
GK said…
Can you please let me know how I can modify this code to connect to a remote data base . I would appreciate if you send me the lines of code
KUPPA said…
Hi, Thanks for this tutorial....
But actually iam searching for login application i.e)username and password are stored in database or server.. when i enterd username&password values server or database will check these two values.. if it matches it will return success otherwise failure.... pls help me :P
Android is an operating system such as mobile devices like smart phones and tablet computers.Android is a Linux base mobile application which is providing very fastest services .This Android Incredible features get good popularity In market.Android has a large community of developers writing applications that extend the functionality of the devices.We are also providing good logic to develop more In this field.
Android app developers
I would like to thank for creating this interesting blog, because its having the good knowledge about android. so its useful to me.

Android developer
ferdaws said…
please how can i connect to my mysql database from this form ???
ans patel said…
pls tell me,
how to login my mail address from my android application???
Er. Vikas Gupta said…
superb... Thanks a lot, its really helpfull to everyone who have no idea of xml (like me ) in creating android basic app.. once again thank you so much.. :)
sudhursun said…
do you have any ideas of creating database and viewing database using will be very useful if you help i am a student doing finalyear project.........
sudhursun said…
Can you help me with creating database using timepicker............I am doing it for final year college project thanks in advance
satheesh said…

Hi this app is very useful to me. YQ
Osama Khalid said…
i dun know what to do with this @override line , em getting some error in onclick (view v) line ,
i dun have any knowledge regarding android , just that i have appointed to do a project on android , so i have to learn it asap ... please guide me thats my first task making a simple login form and em not getting anything .. :(
Osama Khalid said…
i dun know what to do with this @override line , em getting some error in onclick (view v) line ,
i dun have any knowledge regarding android , just that i have appointed to do a project on android , so i have to learn it asap ... please guide me thats my first task making a simple login form and em not getting anything .. :(
bhadaj said…
I am unable to enter the values into EditText....
Can u help me....
mam plz tell me how i can crete my sqldatabase
Irfan Shaikh said…
can u create web app for login using servlets & jsp & import it into ur android project ???
pavankumar said…
Hi Mayuri,

thanks for providng data for login form...i need some more information from that data like how to fetch the same code through database through different un and pwd's???can u please provide if you have that type of data...

Pavan Kumar
Prabhu R said…
Thanks for your post mayuri... This example was quite helpful. I have also referred this site, which looks quite useful. Have a look!!
Deepak Amane said…
Thanks. This Code really helped me out. I want some modification in this code, I want to switch another Screen
I have used the Intent but it is showing me error.. Will u plz. help me.?
Deepak Amane said…
This comment has been removed by the author.
rajesh kadiri said…
hi Mayuri
i want signup page program with database.can u help me
Good One yaar , Thank'z for Your Code.
Anonymous said…
Could you please provide me a login and registration sourse code using sqlite and eclipse:
There should be a reset button on registration page. And after login directed to a new welcome page.

Please provide me this code as soon as possible.
Nauman Shaw said…
Can any body Explain how to authenticate login from remote server through PHP and MysQl.. I have tried several Tutorial nut unable to resolve the issue . My emulator gets stuck when ever i make any request to the server (Xaampp).
nabler rastaman said…
Awesome mayuri

@Nauman Shaw use phonegap man
Sanjay said…
I tried this app and most of it works.
I copied the code snippets from here to a fullscreen app.
My username field overlaps the app name field on the top left?
still trying to find the reason and rectify this
Thanks Mayuri,
Sanjay said…
I found one solution for this - by setting marginTop as a value
Hi, may I know the connectivity coding for the same example shown above?
Thank you
Tsegay Gm said…
please tell me how to handle the error "unfortunately has stopped "

contact me by:
Juan Tomaylla said…
Thanks Akhtar! I used to login in a sqlserver, impressive code!!
Akash Jayant said…
Thanks for sharing this post

Dealersocket Login

Popular posts from this blog

Android PhoneGap Login Example with JQuery-Ajax & Java/Servlet/JDBC

Working with JSON & PhoneGap Application

Getting an Access of Android Java Code to a PhoneGap JavaScript.