Tuesday, December 14, 2010

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="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
     
<TableRow>
<TextView 
android:text="User Name: " 
android:id="@+id/TextView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>

<EditText 
android:text="" 
android:id="@+id/txtUname" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</EditText>
</TableRow>


<TableRow>
<TextView 
android:text="Password: " 
android:id="@+id/TextView02" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>


<EditText 
android:text="" 
android:id="@+id/txtPwd" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:password="true">
</EditText>
</TableRow>


<TableRow>
<Button
android:text="Cancel" 
android:id="@+id/btnCancel" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</Button>


<Button
android:text="Login" 
android:id="@+id/btnLogin" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</Button>


</TableRow>


</TableLayout>



Following is the Activity Code for the Application:


package com.mayuri.login;
import android.app.Activity;
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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        txtUserName=(EditText)this.findViewById(R.id.txtUname);
        txtPassword=(EditText)this.findViewById(R.id.txtPwd);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new OnClickListener() {

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

if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
        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.

~Mayuri



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



41 comments:

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...

Hi.
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...

Hello,,
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 app development said...

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

Android developer said...

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 timepicker...it 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...

Satheesh

Hi this app is very useful to me. YQ

Denis Jaluo said...

gatchu mayuri

Denis Jaluo said...

gatchu mayuri

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....

Kusumakar Avasthi said...

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...

Thanks,
Pavan Kumar

Prabhu R said...

Thanks for your post mayuri... This example was quite helpful. I have also referred this site http://androidtechstuffs.blogspot.in/2013/01/login-application-for-android.html, 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

William Benjamin said...

Good One yaar , Thank'z for Your Code.

amit verma 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.
Thankyou
cse.amver@gmail.com

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,
SanjayB.

Sanjay said...

I found one solution for this - by setting marginTop as a value

SagaDevan JagaNathan said...

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: tsegay.gm@gmail.com

Juan Tomaylla said...

Thanks Akhtar! I used to login in a sqlserver, impressive code!!

Naviya Nair said...

Great and Useful Article.
Java Online Training

Online Java Course

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions








Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Java Course in Chennai

Akash Jayant said...

Thanks for sharing this post

Dealersocket Login