Monday 12 June 2017

Android Login Example Using PHP, MySQL












Android Login Example Using PHP, MySQL and Volley


Hello friends we have already covered a couple of tutorials  for android login example using php mysql.
  1. Android Login Example with Volley Library
  2. Android Login and Registration using PHP and MySQL
But in the above mentioned tutorials, we were not maintaining the login session. Like once user has logged in to our app, user do not need to login again.
So in this android login example we will see how we can do Android User Session Management. And we will give a logout button from where user can logout from our app.

Android Login Example – Video

  • You can check the following video to know exactly what we will be creating in this android log in tutorial.
  • Now if you want to create this android login example, go ahead in this tutorial.

Creating Database and PHP Scripts

  • For this tutorial I am using wamp server.
  • This is my MySQL database.
mysql database
mysql database
  • As you can see I have a very small table with only three columns (id, email and password). You have to create the same.
  • Now we will create two php script. The first one to connect to the database (dbConnect.php).
Quick Tip: Are you are thinking that closing php tag  ‘ ?> ‘ is missing? Actually we do not need the closing tag for the files having only php code on it. You can still put the ?> closing tag but it will not make any difference.
  • The next script to handle our login request. Create a new php file login.php.

Android Login Example

  • Now create a new class named Config.java to store some important constants.

Desiging Android Login Activity

  • First we will define colors. Inside values-> colors.xml write the following code.
  • In the layout file of your login activity write the following code.
  • The above code will produce the following layout. We are not creating an Android Registration Form here. User will directly see the login page.
android login example
android login example
  • Now come to the java code (In my case it is LoginActivity.java).
  • Now we need to code the next activity (Create a new activity for profile ProfileActivity.java).
  • For this activity we need to create a menu for our logout button. So inside menu -> menu.xml write the following.
  • We need to create only a single TextView in our layout file for this activity (activity_profile.xml).
  • Write the following code in ProfileActivity.java
  • Add Internet Permission to Your AndroidManifest.xml 
  • Thats it, run your application now.
android login example
Android Login Example
  • Bingo! its working fine.
  • You can also download my source code from github. Visit the link given below.

0 comments:

Post a Comment