Android Volley Tutorial – User Registration and Login

Hey folks, heres another Android Volley Tutorial. If you remember one of remember one of the previous tutorial which was about creating a Login and Registration system for Android. You can check the post from …

android volley tutorial

Hey folks, heres another Android Volley Tutorial. If you remember one of remember one of the previous tutorial which was about creating a Login and Registration system for Android. You can check the post from below.

In the above mentioned tutorial we learnt how to send http request to our web services to make login and registration system. In this post we will do exactly the same thing but with Volley Library. Using volley library will simplify our task, and it is fast and it manages everything so you don’t need to worry. So lets start this Android Volley Tutorial.

Android Volley Tutorial – Video

  • You can also follow this video tutorial series to learn the same.

Android Volley Tutorial – User Registration and Login

Creating Web Services

  • So first we need the Web Services for User Registration and Login. We also need MySQL Database. Now you can use other technologies for your server side as well. It is obvious not mandatory to use PHP and MySQL only. But here I am using PHP and MySQL.
  • And the best thing here is I will not be doing this thing in this post hahaha 😛 (LOL). Because in the last post which you can see from the below link, we already built web services for the User Registration and Login. And here I will be using the same thing. So go through the link given below first then move further in this post.

Learn Creating Web Services Here

Android Login and Registration

Creating a new Project

  • As always we need a new Android Studio project. So create a project named SimplifiedCoding (You can actually name it whatever you want) with an EmptyActivity.
  • Once your project is loaded create two more activities here named LoginActivity and ProfileActivity.
  • Now lets design the screens first.

User Interface Design

Registration Screen
  • So come inside activity_main.xml and write the following xml code.

  • You will see the following design with the above given xml code.

android registration

Login Screen
  • For the login screen come inside activity_login.xml and write the following xml code.

  • The above code will generate the output as shown below.

user login screen

Profile Screen
  • Lastly we will design the profile screen using the following xml code.

  • You will see the profile screen looking as shown below.

profile screen

Creating Helper Classes

  • It is very important that we organize our code well so that it can be reused. That is why here we are creating different classes for different task. Though we are doing exactly the same we did in the last post.
User Model Class
  • First we will create a class for our User. So create a class named User.java and write the following code inside. The code contains nothing but only the user attributes with a constructor and getters. You can easily do this by right click -> generate -> constructor/ getters.

SharedPrefManager Class
  • In android side to maintain a user login session, here we are using SharedPreferenes. Inside SharedPreferences we will store the data of currently logged in user. So that we can use it in our application. So to handle all the sharedpreferences task at one place we are having this class named SharedPrefmanager.java.

Web Service URLs
  • Create a new class named URLs.java to put all the Web Service URLs at one place. So here I am using a class named URLs.java.

  • Now we have all the helper classes.

Adding Volley Library

  • As in this project we need to use Volley for the network operation, and for this we need to add Volley to this project.
  • For this come inside app level build.gradle file and inside dependencies block add volley.

  • After adding this you need to sync your project.

Adding Internet Permission

  • As networking operations requires internet permission so inside AndroidManifest.xml define the internet permission for the application.

Using Singleton Pattern for Volley

  • As any app requires many network operations. So in this case it is always a good idea to use a single instance of Volley RequestQueue. For this we will use a Singleton Pattern for handling all the request queues.
  • So create a new class named VolleySingleton.java and write the following code.

User Registration

  • Now lets perform the user registration inside MainActivity.java. The code is very simple and it is actually explaining itself. But if you think you have some confusions at some lines, feel free to comment and I will try to help you.

  • If you are facing some problem understanding the codes, you can check the video tutorials given at the starting of this post.

User Profile

  • Come inside ProfileActivity.java and write the following code. Here we are only displaying the User data and we have a button that will let the user logout from the app.

  • Now lastly we will code the LoginActivity.

User Login

  • Come inside LoginActivity.java and write the following code. It is almost same as the User Registration Activity (MainActivity.java).

  • Now you can test the application.
android volley tutorial
Android Volley Tutorial – User Registration and Login
  • Bingo! It is working absolutely fine.

Source Code Download

  • If you are having some troubles creating the project then don’t worry I am giving you the complete source code here. You can download it from below.

[sociallocker id=1372] Android Volley Tutorial – User Registration and Login Source Code [/sociallocker]

So thats all for this Android Volley Tutorial friends. If you found this helpful then please SHARE it. If having any feedbacks, suggestions or queries, please comment it.

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x