Top Banner

of 65

Create a Login and Registration Form in Android Using SQLite Database

Mar 02, 2018

Download

Documents

Sree Nidhi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    1/65

    http://android-emotions.com/create-a-login-and-registration-form-in-android-using-sqlite-database/

    Create a Login and Registration form in Android usingSQLite databasePosted By: Saurabh Kumaron: February 23, 201511 Comments

    Hi Guys, Today i am oin to dis!uss "ith you about !reation o# $oin and reistration #or in %ndroid

    usin S&'ite database( For this thins you must ha)e *no"$ede about S&'ite database in %ndroid(So #or this at #irst i "i$$ dis!uss about S&'ite database and ho" to use it in %ndroid(

    1. escription:

    +n this arti!$e i am usin S&'ite database and a$so i am etendin S&'ite-.enHe$.er !$ass(/ou

    !reate a sub!$ass im.$ementinonCreateS&'iteatabase,on.radeS&'iteatabase, int,

    intand o.tiona$$y on-.enS&'iteatabase,and this !$ass ta*es !are o# o.enin the database i# it

    eists, !reatin it i# it does not, and u.radin it as ne!essary(

    !ublic Constructors of SQLite"pen#elper Class

    .ub$i! S&'ite-.enHe$.er Contet !ontet, Strin name, S&'iteatabase(CursorFa!tory #a!tory, int

    )ersion

    Create a he$.er ob4e!t to !reate, o.en, andor manae a database( This method a$"ays returns )ery

    6ui!*$y( The database is not a!tua$$y !reated or o.ened unti$ one

    o#et7ritab$eatabaseor et8eadab$eatabaseis !a$$ed(

    !arameters

    conte$t: to use to o.en or !reate the database

    name: o# the database #i$e, or nu$$ #or an in9memory database

    http://android-emotions.com/author/saurabhkumar/http://android-emotions.com/create-a-login-and-registration-form-in-android-using-sqlite-database/#commentshttp://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onOpen(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onOpen(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getReadableDatabase()http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getReadableDatabase()http://android-emotions.com/create-a-login-and-registration-form-in-android-using-sqlite-database/#commentshttp://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onOpen(android.database.sqlite.SQLiteDatabase)http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getReadableDatabase()http://android-emotions.com/author/saurabhkumar/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    2/65

    factor%: to use #or !reatin !ursor ob4e!ts, or nu$$ #or the de#au$t

    error#andler:atabaserrorHand$erto be used "hen s6$ite re.orts database !orru.tion, or

    nu$$ to use the de#au$t error hand$er(

    &. Code for Screen design in 'ml&.1 Code for design #ome Screen:

    ;'inear'ayout m$ns:android!ontent=

    android:ba!*round

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    3/65

    ;Button

    android:id"idth.arent=

    android:$ayout>heiht

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    4/65

    ;Dm$ )ersion!ontent=

    android:hint

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    5/65

    ;ditTet

    android:idheihtheiht

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    6/65

    android:$ayout>heihtmarinBottom

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    7/65

    android:$ayout>"idth.arent=

    android:$ayout>heiht.arent=

    android:orientation"idth.arent=

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    8/65

    android:$ayout>heihtheiht

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    9/65

    &.) code for design *elcome screen:

    ;Dm$ )ersion

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    10/65

    (. Code for functionalit% in +A,A

    (.1 Code for #omeScreen

    .a!*ae !om(eam.$e(#orm

    im.ort android(a..(%!ti)ity

    im.ort android(a..(ia$o

    im.ort android(!ontent(+ntent

    im.ort android(os(Bund$e

    im.ort android()ie"(ie"

    im.ort android("idet(Button

    im.ort android("idet(ditTet

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    11/65

    im.ort android("idet(Toast

    .ub$i! !$ass Home%!ti)ity etends %!ti)ity I

    Button btnSin+n, btnSin.

    'oinataBase%da.ter $oinataBase%da.ter

    ?-)erride

    .rote!ted )oid onCreateBund$e sa)ed+nstan!eState I

    su.er(onCreatesa)ed+nstan!eState

    setContentie"8($ayout(a!ti)ity>main

    $oinataBase%da.ter < ne" 'oinataBase%da.terthis

    $oinataBase%da.ter < $oinataBase%da.ter(o.en

    btnSin+n < Button #indie"By+d8(id(buttonSin+

    btnSin. < Button #indie"By+d8(id(buttonSinP

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    12/65

    btnSin.(set-nC$i!*'istenerne" ie"(-nC$i!*'istener I

    .ub$i! )oid onC$i!*ie" ) I

    T-- %uto9enerated method stub

    +ntent intentSinP < ne" +ntentet%..$i!ationContet,

    SinP%!ti)ity(!$ass

    start%!ti)ityintentSinP

    J

    J

    J

    .ub$i! )oid sin+nie" I

    #ina$ ia$o dia$o < ne" ia$oHome%!ti)ity(this

    dia$o(setContentie"8($ayout($oin

    dia$o(setTit$e='oin=

    #ina$ ditTet editTetserame < ditTet dia$o

    (#indie"By+d8(id(editTetserameTo'oin

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    13/65

    #ina$ ditTet editTetPass"ord < ditTet dia$o

    (#indie"By+d8(id(editTetPass"ordTo'oin

    Button btnSin+n < Button dia$o(#indie"By+d8(id(buttonSin+n

    btnSin+n(set-nC$i!*'istenerne" ie"(-nC$i!*'istener I

    .ub$i! )oid onC$i!*ie" ) I

    Strin userame < editTetserame(etTet(toStrin

    Strin .ass"ord < editTetPass"ord(etTet(toStrin

    Strin storedPass"ord < $oinataBase%da.ter

    (etSin$entryuserame

    i# .ass"ord(e6ua$sstoredPass"ord I

    Toast(ma*eTetHome%!ti)ity(this,

    =Conrats: 'oin Su!!ess#u$$=,

    Toast('GTH>'-G

    (sho"

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    14/65

    dia$o(dismiss

    +ntent main < ne" +ntentHome%!ti)ity(this,

    7e$!ome(!$ass

    start%!ti)itymain

    J e$se I

    Toast(ma*eTetHome%!ti)ity(this,

    =ser ame or Pass"ord does

    not mat!h=,

    Toast('GTH>'-G(sho"

    J

    J

    J

    dia$o(sho"

    J

    ?-)erride

    .rote!ted )oid onestroy I

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    15/65

    su.er(onestroy

    $oinataBase%da.ter(!$ose

    J

    J

    (.& Code for Signup Screen and Login Screen:

    .a!*ae !om(eam.$e(#orm

    im.ort android(a..(%!ti)ity

    im.ort android(!ontent(Contet

    im.ort android(!ontent(+ntent

    im.ort android(os(Bund$e

    im.ort android()ie"(ie"

    im.ort android("idet(Button

    im.ort android("idet(ditTet

    im.ort android("idet(Toast

    .ub$i! !$ass SinP%!ti)ity etends %!ti)ity I

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    16/65

    ditTet editTetserame, editTetPass"ord, editTetCon#irmPass"ord

    Button btnCreate%!!ount

    Contet !ontet < this

    'oinataBase%da.ter $oinataBase%da.ter

    ?-)erride

    .rote!ted )oid onCreateBund$e sa)ed+nstan!eState I

    su.er(onCreatesa)ed+nstan!eState

    setContentie"8($ayout(sinu.

    $oinataBase%da.ter < ne" 'oinataBase%da.terthis

    $oinataBase%da.ter < $oinataBase%da.ter(o.en

    editTetserame < ditTet #indie"By+d8(id(editTetserame

    editTetPass"ord < ditTet #indie"By+d8(id(editTetPass"ord

    editTetCon#irmPass"ord < ditTet

    #indie"By+d8(id(editTetCon#irmPass"ord

    btnCreate%!!ount < Button #indie"By+d8(id(buttonCreate%!!ount

    btnCreate%!!ount(set-nC$i!*'istenerne" ie"(-nC$i!*'istener I

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    17/65

    .ub$i! )oid onC$i!*ie" ) I

    Strin userame < editTetserame(etTet(toStrin

    Strin .ass"ord < editTetPass"ord(etTet(toStrin

    Strin !on#irmPass"ord %M, nu$$,

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    21/65

    %T%B%S>8S+-

    J

    .ub$i! 'oinataBase%da.ter o.en thro"s S&'!e.tion I

    db < dbHe$.er(et7ritab$eatabase

    return this

    J

    .ub$i! )oid !$ose I

    db(!$ose

    J

    .ub$i! S&'iteatabase etatabase+nstan!e I

    return db

    J

    .ub$i! )oid insertntryStrin userame, Strin .ass"ord I

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    22/65

    Contenta$ues ne"a$ues < ne" Contenta$ues

    ne"a$ues(.ut=S8%M=, userame

    ne"a$ues(.ut=P%SS7-8=, .ass"ord

    db(insert='-G+=, nu$$, ne"a$ues

    J

    .ub$i! int de$etentryStrin serame I

    Strin "here < =S8%M

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    23/65

    ne" StrinNO I userame J, nu$$, nu$$, nu$$

    i# !ursor(etCount ; 1 I

    !ursor(!$ose

    return =-T +ST=

    J

    !ursor(mo)eToFirst

    Strin .ass"ord < !ursor(etStrin!ursor(etCo$umn+nde=P%SS7-8=

    !ursor(!$ose

    return .ass"ord

    J

    .ub$i! )oid u.datentryStrin userame, Strin .ass"ord I

    Contenta$ues u.dateda$ues < ne" Contenta$ues

    u.dateda$ues(.ut=S8%M=, userame

    u.dateda$ues(.ut=P%SS7-8=, .ass"ord

    Strin "here < =S8%M < D=

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    24/65

    db(u.date='-G+=, u.dateda$ues, "here, ne" StrinNO I userame J

    J

    J

    (.) Code for database #elper class.

    .a!*ae !om(eam.$e(#orm

    im.ort android(!ontent(Contet

    im.ort android(database(s6$ite(S&'iteatabase

    im.ort android(database(s6$ite(S&'iteatabase(CursorFa!tory

    im.ort android(database(s6$ite(S&'ite-.enHe$.er

    im.ort android(uti$('o

    .ub$i! !$ass ataBaseHe$.er etends S&'ite-.enHe$.er I

    .ub$i! ataBaseHe$.erContet !ontet, Strin name, CursorFa!tory #a!tory,

    int )ersion I

    su.er!ontet, name, #a!tory, )ersion

    J

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    25/65

    ?-)erride

    .ub$i! )oid onCreateS&'iteatabase >db I

    >db(ee!S&''oinataBase%da.ter(%T%B%S>C8%T

    J

    ?-)erride

    .ub$i! )oid on.radeS&'iteatabase >db, int >o$dersion, int >ne"ersion I

    'o("=Tas*B%da.ter=, =.radin #rom )ersion = >o$dersion = to =

    >ne"ersion =, "hi!h "i$$ destroy a$$ o$d data=

    >db(ee!S&'=8-P T%B' +F +STS = =TMP'%T=

    onCreate>db

    J

    J

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    26/65

    ). Androidanifest.$ml file

    ;Dm$ )ersion

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    27/65

    android:name

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    28/65

    ;a..$i!ationA

    ;mani#estA

    . o* app is created and output is belo*:

    .1 After clic0 on run first screen

    .& Clic0 on signup screen

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    29/65

    .( f an% field is 2acant in signup screen

    .) if pass*ord and confirm pass*ord is not equal.

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    30/65

    . After successful registration.

    .3 Clic0 on login button.

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    31/65

    .4 After entering *rong user name or pass*ord.

    .5 After entering right credentials 6*elcome screen7

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    32/65

    So uys, this is the basi! and mandatory thins that you ha)e to *no" be#ore ma*in any $oin and

    reistration #eature in your a.. usin S&'ite database( and "ith the he$. o# this you !an ma*e you

    a.. se!ure and !on#identia$(

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    33/65

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-

    example/

    %ndroid 'ayouts #or 'oin 8eistration %..$i!ation:

    main.$ml :

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    34/65

    android:layout_width="'ill_parent"

    android:layout_height="wrap_content"

    android:text="$ign %n"

    android:on(lick="sign%n"/>

    Login.$ml

    D

    1

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    35/65

    2

    3

    4

    !

    "

    #

    $

    1%

    11

    12

    13

    14

    1

    1!

    1"

    1#

    1$

    2%

    21

    22

    23

    24

    2

    2!

    2"

    http://schemas.android.com/apk/res/androidhttp://schemas.android.com/apk/res/android
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    36/65

    2#

    2$

    3%

    31

    32

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    41

    42

    43

    44

    4

    4!

    4"

    4#

    4$

    %

    1

    2

    3

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    37/65

    4

    !

    "

    #

    $

    (.signup.$ml

    D

    1

    2

    3

    4

    !

    "

    #

    $

    1%

    11

    12

    13

    14

    1

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    38/65

    1!

    1"

    1#

    1$

    2%

    21

    22

    23

    24

    2

    2!

    2"

    2#

    2$

    3%

    31

    32

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    41

    android:id="!id/edit1ext)ser&ame"

    android:hint=")ser &ame"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    >

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    39/65

    42

    43

    44

    4

    4!

    4"

    4#

    4$

    %

    1

    2

    3

    4

    !

    android:hint="(on'irm *assword"

    android:input1ype="text*assword"/>

    o" Create Ra)a Fi$es:

    7e ha)e used Ra)a #i$es in this a..$i!ation( /ou !an a$so #ind !om.$ete sour!e !ode des!ri.tion inside

    the !ode, on!e you do"n$oad !om.$ete !ode #rom here(

    1.#omeActi2it%.8a2a

    D

    1

    2

    3

    4

    !

    package6

    importandroid.app.4ctivity6

    importandroid.app.7ialog6

    importandroid.content.%ntent6

    importandroid.os.undle6

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    40/65

    "

    #

    $

    1%

    11

    12

    13

    14

    1

    1!

    1"

    1#

    1$

    2%

    21

    22

    23

    24

    2

    2!

    2"

    2#

    2$

    3%

    31

    32

    importandroid.view.8iew6

    importandroid.widget.utton6

    importandroid.widget.0dit1ext6

    importandroid.widget.1oast6

    pu#licclass9ome4ctivity extends4ctivity

    utton #tn$ign%n;#tn$ign)p6

    Login7ataase4dapter login7ataase4dapter6

    !verride

    protectedvoidon(reateundle saved%nstance$tate

    super.on(reatesaved%nstance$tate6

    set(ontent8iew?.layout.main6

    // create a instance o' $@Lite 7ata#ase

    login7ataase4dapter=newLogin7ataase4dapterthis6

    login7ataase4dapter=login7ataase4dapter.open6

    // Aet 1he ?e''erence ' uttons

    #tn$ign%n=utton'ind8iewy%d?.id.#utton$ign%&6

    #tn$ign)p=utton'ind8iewy%d?.id.#utton$ign)*6

    // $et n(lick Listener on $ign)p #utton

    #tn$ign)p.setn(lickListenernew8iew.n(lickListener

    pu#licvoidon(lick8iew v

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    41/65

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    41

    42

    43

    44

    4

    4!

    4"

    4#

    4$

    %

    1

    2

    3

    4

    !

    "

    #

    // 17 4utogenerated method stu#

    /// (reate %ntent 'or $ign)p4ctivity a#d $tart 1he 4ctivity

    %ntent intent$ign)*=new%ntentget4pplication(ontext;$ign)*4ctivity.class6

    start4ctivityintent$ign)*6

    B

    B6

    B

    // Cethos to handle(lick 0vent o' $ign %n utton

    pu#licvoidsign%n8iew 8

    'inal7ialog dialog = new7ialog9ome4ctivity.this6

    dialog.set(ontent8iew?.layout.login6

    dialog.set1itle"Login"6

    // get the ?e''erences o' views

    'inal0dit1ext edit1ext)ser&ame=0dit1extdialog.'ind8iewy%d?.id.edit1ext)ser&

    'inal0dit1ext edit1ext*assword=0dit1extdialog.'ind8iewy%d?.id.edit1ext*assw

    utton #tn$ign%n=uttondialog.'ind8iewy%d?.id.#utton$ign%n6

    // $et n (lickListener

    #tn$ign%n.setn(lickListenernew8iew.n(lickListener

    pu#licvoidon(lick8iew v

    // get 1he )ser name and *assword

    $tring user&ame=edit1ext)ser&ame.get1ext.to$tring6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    42/65

    $

    !%

    !1

    !2

    !3

    !4

    !

    !!

    !"

    !#

    !$

    "%

    "1

    "2

    "3

    "4

    "

    "!

    ""

    "#

    "$

    #%

    #1

    #2

    #3

    #4

    $tring password=edit1ext*assword.get1ext.to$tring6

    // 'etch the *assword 'orm data#ase 'or respective user name

    $tring stored*assword=login7ataase4dapter.get$inlge0ntryuser&ame6

    // check i' the $tored password matches with *assword entered #y user

    i'password.e2ualsstored*assword

    1oast.make1ext9ome4ctivity.this; "(ongrats: Login $uccess'ull"; 1oast.L0&A19_L

    dialog.dismiss6

    B

    else

    1oast.make1ext9ome4ctivity.this; ")ser &ame or *assword does not match";

    1oast.L0&A19_L&A.show6

    B

    B

    B6

    dialog.show6

    B

    !verride

    protectedvoidon7estroy

    super.on7estroy6

    // (lose 1he 7ata#ase

    login7ataase4dapter.close6

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    43/65

    #

    #!

    #"

    ##

    B

    &. Sign9!Acti2it%.+a2a:

    D

    1

    2

    3

    4

    !

    "

    #

    $

    1%

    11

    12

    13

    14

    1

    1!

    1"

    1#

    package6

    importandroid.app.4ctivity6

    importandroid.os.undle6

    importandroid.view.8iew6

    importandroid.widget.utton6

    importandroid.widget.0dit1ext6

    importandroid.widget.1oast6

    pu#licclass$ign)*4ctivity extends4ctivity

    0dit1ext edit1ext)ser&ame;edit1ext*assword;edit1ext(on'irm*assword6

    utton #tn(reate4ccount6

    Login7ataase4dapter login7ataase4dapter6

    !verride

    protectedvoidon(reateundle saved%nstance$tate

    super.on(reatesaved%nstance$tate6

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    44/65

    1$

    2%

    21

    22

    23

    24

    2

    2!

    2"

    2#

    2$

    3%

    31

    32

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    41

    42

    43

    44

    set(ontent8iew?.layout.signup6

    // get %nstance o' 7ata#ase 4dapter

    login7ataase4dapter=newLogin7ataase4dapterthis6

    login7ataase4dapter=login7ataase4dapter.open6

    // Aet ?e''erences o' 8iews

    edit1ext)ser&ame=0dit1ext'ind8iewy%d?.id.edit1ext)ser&ame6

    edit1ext*assword=0dit1ext'ind8iewy%d?.id.edit1ext*assword6

    edit1ext(on'irm*assword=0dit1ext'ind8iewy%d?.id.edit1ext(on'irm*assword6

    #tn(reate4ccount=utton'ind8iewy%d?.id.#utton(reate4ccount6

    #tn(reate4ccount.setn(lickListenernew8iew.n(lickListener

    pu#licvoidon(lick8iew v

    // 17 4utogenerated method stu#

    $tring user&ame=edit1ext)ser&ame.get1ext.to$tring6

    $tring password=edit1ext*assword.get1ext.to$tring6

    $tring con'irm*assword=edit1ext(on'irm*assword.get1ext.to$tring6

    // check i' any o' the 'ields are vaccant

    i'user&ame.e2uals""DDpassword.e2uals""DDcon'irm*assword.e2uals""

    1oast.make1extget4pplication(ontext; "3ield 8accant"; 1oast.L0&A19_L&A.sho

    return6

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    45/65

    4

    4!

    4"

    4#

    4$

    %

    1

    2

    3

    4

    !

    "

    #

    $

    !%

    !1

    !2

    !3

    !4

    !

    !!

    !"

    !#

    !$

    // check i' #oth password matches

    i'Epassword.e2ualscon'irm*assword

    1oast.make1extget4pplication(ontext; "*assword does not match";

    1oast.L0&A19_L&A.show6

    return6

    B

    else

    // $ave the 7ata in 7ata#ase

    login7ataase4dapter.insert0ntryuser&ame; password6

    1oast.make1extget4pplication(ontext; "4ccount $uccess'ully (reated ";

    1oast.L0&A19_L&A.show6

    B

    B

    B6

    B

    !verride

    protectedvoidon7estroy

    // 17 4utogenerated method stu#

    super.on7estroy6

    login7ataase4dapter.close6

    B

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    46/65

    (. ataase#elper.+a2a:

    D

    1

    2

    3

    4

    !

    "

    #

    $

    1%

    11

    12

    13

    14

    1

    1!

    1"

    1#

    1$

    2%

    21

    22

    23

    package 6

    importandroid.content.(ontext6

    importandroid.data#ase.s2lite.$@Lite7ata#ase6

    importandroid.data#ase.s2lite.$@Lite7ata#ase.(ursor3actory6

    importandroid.data#ase.s2lite.$@Litepen9elper6

    importandroid.util.Log6

    pu#licclass7ataase9elper extends$@Litepen9elper

    pu#lic7ataase9elper(ontext context; $tring name;(ursor3actory 'actory; intve

    supercontext; name; 'actory; version6

    B

    // (alled when no data#ase exists in disk and the helper class needs

    // to create a new one.

    !verride

    pu#licvoidon(reate$@Lite7ata#ase _d#

    _d#[email protected]$0_(?04106

    B

    // (alled when there is a data#ase version mismatch meaning that the version

    // o' the data#ase on disk needs to #e upgraded to the current version.

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    47/65

    24

    2

    2!

    2"

    2#

    2$

    3%

    31

    32

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    !verride

    pu#licvoidon)pgrade$@Lite7ata#ase _d#; int_old8ersion; int_new8ersion

    // Log the version upgrade.

    Log.w"1ask74dapter"; ")pgrading 'rom version "_old8ersion " to "_new8ersold data"6

    // )pgrade the existing data#ase to con'orm to the new version. Cultiple

    // previous versions can #e handled #y comparing _old8ersion and _new8ersion

    // values.

    // 1he simplest case is to drop the old ta#le and create a new one.

    _d#.exec$@L"7?* 14L0 %3 0F%$1$ " "10C*L410"6

    // (reate a new one.

    on(reate_d#6

    B

    B

    ). LoginataaseAdapter.+a2a

    D

    1

    2

    3

    4

    package6

    importandroid.content.(ontent8alues6

    importandroid.content.(ontext6

    importandroid.data#ase.(ursor6

    importandroid.data#ase.$@L0xception6

    http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/http://www.appsinfoway.com/android-registration-login-using-sqlite-database-example/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    48/65

    !

    "

    #

    $

    1%

    11

    12

    13

    14

    1

    1!

    1"

    1#

    1$

    2%

    21

    22

    23

    24

    2

    2!

    2"

    2#

    2$

    3%

    31

    importandroid.data#ase.s2lite.$@Lite7ata#ase6

    pu#licclassLogin7ataase4dapter

    static'inal$tring 74144$0_&4C0 = "login.d#"6

    static'inalint74144$0_80?$%& = ,6

    pu#licstatic'inalint&4C0_(L)C& = ,6

    // 17: (reate pu#lic 'ield 'or each column in your ta#le.

    // $@L $tatement to create a new data#ase.

    static'inal$tring 74144$0_(?0410 = "create ta#le ""LA%&"

    " ""%7"" integer primary key autoincrement;" ")$0?&4C0 text;*4$$G?7 text6

    // 8aria#le to hold the data#ase instance

    pu#lic$@Lite7ata#ase d#6

    // (ontext o' the application using the data#ase.

    private'inal(ontext context6

    // 7ata#ase open/upgrade helper

    private7ataase9elper d#9elper6

    pu#licLogin7ataase4dapter(ontext _context

    context = _context6

    d#9elper = new7ataase9elpercontext; 74144$0_&4C0; null; 74144$0_80?$%&6

    B

    pu#licLogin7ataase4dapter open throws$@L0xception

    d# = d#9elper.getGrita#le7ata#ase6

    returnthis6

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    49/65

    32

    33

    34

    3

    3!

    3"

    3#

    3$

    4%

    41

    42

    43

    44

    4

    4!

    4"

    4#

    4$

    %

    1

    2

    3

    4

    !

    "

    pu#licvoidclose

    d#.close6

    B

    pu#lic$@Lite7ata#ase get7ata#ase%nstance

    returnd#6

    B

    pu#licvoidinsert0ntry$tring user&ame;$tring password

    (ontent8alues new8alues = new(ontent8alues6

    // 4ssign values 'or each row.

    new8alues.put")$0?&4C0"; user&ame6

    new8alues.put"*4$$G?7";password6

    // %nsert the row into your ta#le

    d#.insert"LA%&"; null; new8alues6

    ///1oast.make1extcontext; "?eminder %s $uccess'ully $aved"; 1oast.L0&A19_L&A

    B

    pu#licintdelete0ntry$tring )ser&ame

    //$tring id=$tring.value'%76

    $tring where=")$0?&4C0=+"6

    intnum#er30ntries7eleted= d#.delete"LA%&"; where; new$tringHI)ser&ameB 6

    // 1oast.make1extcontext; "&um#er 'o 0ntry 7eleted $uccess'ully : "num#er30n

    1oast.L0&A19_L&A.show6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    50/65

    #

    $

    !%

    !1

    !2

    !3

    !4

    !

    !!

    !"

    !#

    !$

    "%

    "1

    "2

    "3

    "4

    "

    "!

    ""

    "#

    "$

    #%

    #1

    #2

    #3

    returnnum#er30ntries7eleted6

    B

    pu#lic$tring get$inlge0ntry$tring user&ame

    (ursor cursor=d#.2uery"LA%&"; null; " )$0?&4C0=+"; new$tringHIuser&ameB; nul

    i'cursor.get(ount

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    51/65

    #4

    #

    #!

    #"

    https://code&one4.wordpress.com/2%12/11/1$/android-login-system-using-sqlite/

    Android Login System using SQLite

    1;",

    https://codezone4.wordpress.com/2012/11/19/android-login-system-using-sqlite/https://codezone4.wordpress.com/2012/11/19/android-login-system-using-sqlite/
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    52/65

    + ha)e a$ready "ritten se)era$ .osts reardin %ndroid database a..$i!ations( This .ost miht be simi$ar tothose tuts( Ho"e)er this is more !om.$ete %ndroid 'oin System "hi!h uses S&'ite as its database( %$$

    #i$es !an be do"n$oaded hereorthere

    'ets !reate the )ie"( #irst( But +m not oin to sho" it in the .ost( Rust t"o tet boes #or username and

    .ass"ord, t"o buttons #or $oin and reister(

    #elper.8a2a

    1

    2

    3

    4

    packagecom.my.mem#ers6

    importandroid.content.(ontext6

    importandroid.data#ase.s2lite.$@Lite7ata#ase6

    http://downloads.ziddu.com/download/24178581/Members.rar.htmlhttp://downloads.ziddu.com/download/24224436/Members.zip.htmlhttp://downloads.ziddu.com/download/24224436/Members.zip.htmlhttp://downloads.ziddu.com/download/24178581/Members.rar.htmlhttp://downloads.ziddu.com/download/24224436/Members.zip.html
  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    53/65

    !

    "

    #

    $

    1

    %

    1

    1

    1

    2

    1

    3

    1

    4

    1

    1

    !

    1

    "

    1#

    1

    $

    2

    importandroid.data#ase.s2lite.$@Litepen9elper6

    pu#licclass79elper extends$@Litepen9elper

    privatestatic'inal$tring 74144$0_&4C0 = "mem#ersd#"6

    privatestatic'inalint74144$0_80?$%& = ,6

    privatestatic'inal$tring 74144$0_(?0410 = "(?0410 14L0 _id integer primary key autoincremen

    pu#lic79elper(ontext context

    supercontext; 74144$0_&4C0; null; 74144$0_80?$%&6

    B

    !verride

    pu#licvoidon(reate$@Lite7ata#ase d#

    d#.exec$@L74144$0_(?04106

    B

    !verride

    pu#licvoidon)pgrade$@Lite7ata#ase d#; intarg,; intargJ

    d#.exec$@L"7?* 14L0 %3 0F%$1$ mem#ers"6

    on(reated#6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    54/65

    %

    2

    1

    2

    2

    2

    3

    2

    4

    2

    2

    !

    2

    "

    2

    #

    2

    $

    3

    %

    B

    B

    Adapter.8a2a

    1

    2

    3

    packagecom.my.mem#ers6

    importandroid.content.(ontent8alues6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    55/65

    4

    !

    "

    #

    $

    1

    %

    1

    1

    1

    2

    1

    3

    14

    1

    1

    !

    1

    "

    1

    #

    1

    $

    importandroid.content.(ontext6

    importandroid.data#ase.(ursor6

    importandroid.data#ase.$@L0xception6

    importandroid.data#ase.s2lite.$@Lite7ata#ase6

    pu#licclass74dapter

    privatestatic'inal$tring 74144$0_14L0 = "mem#ers"6

    pu#licstatic'inal$tring K0_?G_%7 = "_id"6

    pu#licstatic'inal$tring K0_)$0?&4C0 = "username"6

    pu#licstatic'inal$tring K0_*4$$G?7 = "password"6

    $@Lite7ata#ase m7#6

    (ontext m(tx6

    79elper m7#9elper6

    pu#lic74dapter(ontext context

    this.m(tx = context6

    B

    pu#lic74dapter open throws$@L0xception

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    56/65

    2

    %

    2

    1

    2

    2

    2

    3

    2

    4

    2

    2

    !

    2

    "

    2

    #

    2

    $

    3

    %

    3

    1

    3

    2

    3

    m7#9elper = new79elperm(tx6

    m7# = m7#9elper.getGrita#le7ata#ase6

    returnthis6

    B

    pu#licvoidclose

    m7#9elper.close6

    B

    pu#liclongregister$tring user;$tring pw

    (ontent8alues initial8alues = new(ontent8alues6

    initial8alues.putK0_)$0?&4C0; user6

    initial8alues.putK0_*4$$G?7; pw6

    returnm7#.insert74144$0_14L0; null; initial8alues6

    B

    pu#lic#ooleanLogin$tring username; $tring password throws$@L0xception

    (ursor m(ursor = m7#.raw@uery"$0L0(1 M 3?C " 74144$0_14L0 " G90?0 username=+ 4&7 password=

    i'm(ursor E= null

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    57/65

    3

    3

    4

    3

    3

    !

    3

    "

    3

    #

    3

    $

    4

    %

    4

    1

    4

    2

    4

    3

    4

    4

    4

    4

    !

    i'm(ursor.get(ount > -

    returntrue6

    B

    B

    return'alse6

    B

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    58/65

    4

    "

    4

    #

    4

    $

    %

    1

    2

    3

    4

    !

    "

    embersActi2it%

    1

    2

    packagecom.my.mem#ers6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    59/65

    3

    4

    !

    "

    #

    $

    1%

    1

    1

    1

    2

    1

    3

    1

    4

    1

    1

    !

    1

    "

    1

    #

    importandroid.app.4ctivity6

    importandroid.content.(ontext6

    importandroid.data#ase.$@L0xception6

    importandroid.os.undle6

    importandroid.util.Log6

    importandroid.view.8iew6

    importandroid.view.8iew.n(lickListener6

    importandroid.view.inputmethod.%nputCethodCanager6

    importandroid.widget.utton6

    importandroid.widget.0dit1ext6

    importandroid.widget.1oast6

    pu#licclassCem#ers4ctivity extends4ctivity

    74dapter d#4dapter6

    0dit1ext txt)ser&ame6

    0dit1ext txt*assword6

    utton #tnLogin6

    utton #tn?egister6

    !verride

    pu#licvoidon(reateundle saved%nstance$tate

    super.on(reatesaved%nstance$tate6

    set(ontent8iew?.layout.main6

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    60/65

    1

    $

    2

    %

    2

    1

    2

    2

    2

    3

    2

    4

    2

    2

    !

    2

    "

    2

    #

    2

    $

    3

    %

    3

    1

    3

    txt)ser&ame = 0dit1ext 'ind8iewy%d?.id.et_user6

    txt*assword = 0dit1ext 'ind8iewy%d?.id.et_pw6

    #tnLogin = utton 'ind8iewy%d?.id.#tn_login6

    #tn?egister = utton 'ind8iewy%d?.id.#tn_reg6

    d#4dapter = new74dapterthis6

    d#4dapter.open6

    #tnLogin.setn(lickListenernewn(lickListener

    !verride

    pu#licvoidon(lick8iew arg-

    %nputCethodCanager imm = %nputCethodCanager get$ystem$ervice(ontext.%&*)1_C0197_$0?8%(06

    imm.hide$o't%nput3romGindowtxt)ser&ame.getGindow1oken; -6

    imm.hide$o't%nput3romGindowtxt*assword.getGindow1oken; -6

    $tring username = txt)ser&ame.get1ext.to$tring6

    $tring password = txt*assword.get1ext.to$tring6

    i'

    username.length > -

    NN password.length > -

    try

    i'd#4dapter.Loginusername; password

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    61/65

    2

    3

    3

    3

    4

    3

    3

    !

    3

    "

    3

    #

    3

    $

    4

    %

    4

    1

    4

    2

    4

    3

    4

    4

    4

    1oast.make1extCem#ers4ctivity.this;

    "$uccess'ully Logged %n"; 1oast.L0&A19_L&A

    .show6

    B else

    1oast.make1extCem#ers4ctivity.this;

    "%nvalid username or password";

    1oast.L0&A19_L&A.show6

    B

    B catch0xception e

    1oast.make1extCem#ers4ctivity.this; "$ome pro#lem occurred";

    1oast.L0&A19_L&A.show6

    B

    B else

    1oast.make1extCem#ers4ctivity.this;

    ")sername or *assword is empty"; 1oast.L0&A19_L&A.show6

    B

    B

    B6

    #tn?egister.setn(lickListenernewn(lickListener

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    62/65

    4

    !

    4

    "

    4

    #

    4

    $

    %

    1

    2

    3

    4

    !

    "

    #

    $

    !verride

    pu#licvoidon(lick8iew arg-

    %nputCethodCanager imm = %nputCethodCanager get$ystem$ervice(ontext.%&*)1_C0197_$0?8%(06

    imm.hide$o't%nput3romGindowtxt)ser&ame.getGindow1oken; -6

    imm.hide$o't%nput3romGindowtxt*assword.getGindow1oken; -6

    try

    $tring username = txt)ser&ame.get1ext.to$tring6

    $tring password = txt*assword.get1ext.to$tring6

    longi = d#4dapter.registerusername; password6

    i'i E= ,

    1oast.make1extCem#ers4ctivity.this; "ou have success'ully registered";1oast.L0&A19_L&A.show

    B catch$@L0xception e

    1oast.make1extCem#ers4ctivity.this; "$ome pro#lem occurred";

    1oast.L0&A19_L&A.show6

    B

    B

    B6

    B

    B

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    63/65

    !

    %

    !

    1

    !

    2

    !

    3

    !

    4

    !

    !

    !

    !

    "

    !

    #

    !

    $

    "

    %

    "

    1

    "

    2

    "

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    64/65

    3

    "

    4

    "

    "

    !

    "

    "

    "

    #

    "

    $

    #

    %

    #

    1

    #

    2

    #

    3

    #

    4

    #

    #

    !

  • 7/26/2019 Create a Login and Registration Form in Android Using SQLite Database

    65/65

    #

    "

    #

    #

    #

    $

    $

    %

    $

    1

    $

    2

    $

    3

    $

    4