Skip to main content

Login Application using Database with dialog demo

Follow Below Steps for make simple login applicaiton in Android using database with Dialog demo.

1)DataBaseDemoActivity.java

This file diplay login page and trasfer two edit text data into second activity........ 


package database.co.in;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class DataBaseDemoActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    EditText mtxt_email, mtxt_password;
    Button mLogin;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mtxt_email = (EditText)findViewById(R.id.editEmail_id);
        mtxt_password = (EditText)findViewById(R.id.editPassword);
        mLogin = (Button)findViewById(R.id.button1);
        mLogin.setOnClickListener(this);
       
    }
@Override
public void onClick(View v) {
String email = mtxt_email.getText().toString();
String password = mtxt_password.getText().toString();
System.out.println("Email id:-"+email);
System.out.println("Password:-"+password);


Intent dbintent = new Intent(this.getApplicationContext(),DbEntry.class);
dbintent.putExtra("p_email", email);
dbintent.putExtra("p_password", password);

startActivity(dbintent);

}
}

2)main.xml

This is login page gui.. also this file need one header.xml which include externally.......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/apple1" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <TextView
            android:id="@+id/textEmail_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="69dp"
            android:text="Email ID"
            android:textSize="20dp"
            android:gravity="center|left"
            android:textColor="@android:color/holo_purple" />

        <EditText
            android:id="@+id/editEmail_id"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_alignLeft="@+id/button1"
            android:layout_alignRight="@+id/button1"
            android:layout_below="@+id/textEmail_id"
            android:layout_marginTop="10dp" />

        <TextView
            android:id="@+id/textPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textEmail_id"
            android:layout_below="@+id/editEmail_id"
            android:text="Password"
            android:textSize="20dp"
            android:textColor="@android:color/holo_purple" />

        <EditText
            android:id="@+id/editPassword"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_alignLeft="@+id/editEmail_id"
            android:layout_alignRight="@+id/button1"
            android:layout_below="@+id/textPassword"
            android:layout_marginTop="10dp" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editPassword"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="24dp"
            android:background="@drawable/login" />

        <include layout="@layout/header"/>
    </RelativeLayout>

</LinearLayout>
3) header.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
      >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="35dp"
        android:text="Welcome To @pple"
        android:textSize="25dp"
        android:textColor="@android:color/holo_purple" />

</LinearLayout>

4) DbEntry.java

Below code for database logic..... and show Dialog in second page check. it


package database.co.in;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.widget.Toast;

public class DbEntry extends Activity {
SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.out.println("All iz well. ");
Intent getdbintent = getIntent();
String email = getdbintent.getStringExtra("p_email");
String password = getdbintent.getStringExtra("p_password");
db = openOrCreateDatabase("login.db",SQLiteDatabase.CREATE_IF_NECESSARY ,null);
String createTable = "CREATE TABLE IF NOT EXISTS info ("
                + "Emailid TEXT,"
                + "PassWord TEXT);";
db.execSQL(createTable);
String insertData = "INSERT or replace INTO info (Emailid, PassWord) VALUES('"+email+"','"+password+"')" ;    
db.execSQL(insertData);
db.close();
System.out.println("All iz well.database has benn insert successfully.  ");
Toast.makeText(getApplicationContext(), "welcome to o@k Tech"+email+"Password+"+password, Toast.LENGTH_LONG).show();
showDialog(1);
}
protected Dialog onCreateDialog(int i) {
Dialog dialog = null;
switch (i) {
case 1:
dialog = new Dialog(this);
dialog.setTitle("Welcome to O@k Tech......  ....");
dialog.setContentView(R.layout.dialog);
break;

default:
break;
}

return dialog;

}


}
5) dialog.xml

This file content only one button which is display on dialog box .



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Thanx to Login........." />

    </LinearLayout>



6) AndroidManiFest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="database.co.in"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".DataBaseDemoActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity
            android:label="@string/app_name"
            android:name=".DbEntry" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Output and Require Backgroud images for this project.......:





Application Output:- 
 





Comments

  1. this Application develop in api level- 15

    ReplyDelete
  2. Replies
    1. ya bro.... thanx............. kok divas banavo bhi android install kri ne

      Delete
  3. Replies
    1. Ya thanx...... bro.... and biju kay new lage to ke abhi application banavine muku......

      Delete
  4. bro...khub saras..m anroid begginer ...su bija koi simple demos 6?sqlite mate..please share karjo...ne..my id:"jigarce007@gmail.com"

    thanx bro..!

    ReplyDelete

Post a Comment

Popular posts from this blog

Audio Recording in Android

Simple State Diagram for Media Recorder... Here Sequence of Method call is as per state diagram of media Recorder .... Otherwise Invalid sate call Error will be Occur........ Steps: 1) Also her two permission add in Android manifest file <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 2) This is java file coding  audiorecording.java package com.example.recording; import java.io.File; import java.io.FileDescriptor; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import ...

Android Activity

An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with  setContentView(View) . While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with  windowIsFloating  set) or embedded inside of another activity (using  ActivityGroup ). There are two methods almost all subclasses of Activity will implement: onCreate(Bundle)  is where you initialize your activity. Most importantly, here you will usually call  setContentView(int)  with a layout resource defining your UI, and using  findViewById(int)  to retrieve the widgets in that UI that you need to interact with programmatically. onPause()  is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point...