FullStack Android Tutorial – Android Login and Registration Tutorial with PHP MySQL

To learn software development, you must first understand the foundation of Programming Language before you can start learning software development.
Want to understand (OOD) Object Oriented Design Concept should know Java more

Java is a very popular Programming Language in banking, finance and financial technology industries because it provides security and is very useful for building overloaded programs that can handle large amounts of data.
How many Android phones are there? 2.5 billion !!!! How many Android apps are there? 2.9 million !!!!
Java is the most popular Programming Language today, and most Android mobile applications are developed in Java
The average monthly salary of Java Programmer and Android Developer is about
Master the most popular technologies and equip enough knowledge to stay competitive in the rapidly changing technology market.
The first step in programming, whether it is mobile phone development or artificial intelligence programs, the establishment of a website Programming is a technology that must be mastered.
People who want to know the concept of (OOD) Object Oriented Design
Suitable for anyone interested in joining the IT industry. Suitable for parents to understand the progress of children. Suitable for project managers to understand and communicate with IT people

Use real application code examples to teach Java programming, Android mobile phone programs The most basic Object, Register, Login


What is Java


public class MyClass {
public static void main(String[] args) {
System.out.println("Hello World");

Creating Web Services

Why Web Services

Our Android app need the PHP API web service that  between server and the application, so the app can access the database. For this we use Web Services often called APIs, ore more specifically a RESTful API. Now here I am not discussing very much about Rest APIs or Web Services. You can check the below tutorials if you want to explore these things further.


Creating Database

  • We need to following database table.

CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`password` text NOT NULL,
`password_str` varchar(100) DEFAULT NULL,
`first_name` varchar(50) DEFAULT NULL,
`last_name` varchar(50) DEFAULT NULL,
`description` varchar(100) DEFAULT NULL,
`dateofbirth` date NOT NULL,
`gender` varchar(6) NOT NULL,
`user_counter` int(20) NOT NULL DEFAULT '0',
`admin` int(10) NOT NULL DEFAULT '0',
`trainer` int(10) NOT NULL DEFAULT '0',

Connecting to the Database

  • we need to create a database connection file named DbConnect.php. We will use this file to connect to the database. So write the following code inside.


$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";

Building PHP API Web Services

  • So for this create a new php file named Api.php. Inside this file we will handle all the API calls. Currently we have only two the User Registration and User Login.
  • So write the following code inside Api.php.


Android Login and Registration

Now here comes the android part. The first thing we will do on the android side is the register operation. So lets create a new Android Studio.


Creating a New Android Project

  • Now create an android project with Empty Activity. I created a project named AndroidTutorial.
  • Once the project is loaded we will create two more activities in our project. As we will have 3 screens so first create all the 3 screens. The first screen is created by default we need to create the other two. For this right click on your package go to new -> activity -> EmptyActivity. Do this two times and create LoginActivity and ProfileActivity.
  • So finally we have MainActivity for registration, LoginActivity for login and ProfileActivity for the user profile that we will show after login.


package com.myclassstudio.album;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Intent;
import android.view.View;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;
import org.json.JSONException;

public class MainActivity extends AppCompatActivity {

EditText editTextUsername, editTextEmail, editTextPassword;
RadioGroup radioGroupGender;
ProgressBar progressBar;

public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

RequestQueue queue;
JsonObjectRequest request;
Map<String, String> map = new HashMap<String, String>();

protected void onCreate(Bundle savedInstanceState) {

progressBar = (ProgressBar) findViewById(R.id.progressBar);

//if the user is already logged in we will directly start the profile activity
if (SharedPrefManager.getInstance(this).isLoggedIn()) {
startActivity(new Intent(this, ProfileActivity.class));

editTextUsername = (EditText) findViewById(R.id.editTextUsername);
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
radioGroupGender = (RadioGroup) findViewById(R.id.radioGender);

findViewById(R.id.buttonRegister).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//if user pressed on button register
//here we will register the user to server

findViewById(R.id.textViewLogin).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//if user pressed on login
//we will open the login screen
startActivity(new Intent(MainActivity.this, LoginActivity.class));

private void registerUser() {
final String username = editTextUsername.getText().toString().trim();
final String email = editTextEmail.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();

final String gender = ((RadioButton) findViewById(radioGroupGender.getCheckedRadioButtonId())).getText().toString();

//first we will do the validations

if (TextUtils.isEmpty(username)) {
editTextUsername.setError("Please enter username");

if (TextUtils.isEmpty(email)) {
editTextEmail.setError("Please enter your email");

if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
editTextEmail.setError("Enter a valid email");

if (TextUtils.isEmpty(password)) {
editTextPassword.setError("Enter a password");

StringRequest stringRequest = new StringRequest(Request.Method.POST, URLs.URL_REGISTER,
new Response.Listener<String>() {
public void onResponse(String response) {

try {
//converting response to json object
JSONObject obj = new JSONObject(response);

//if no error in response
if (!obj.getBoolean("error")) {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();

//getting the user from the response
JSONObject userJson = obj.getJSONObject("user");

//creating a new user object
User user = new User(

//storing the user in shared preferences

//starting the profile activity
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
} else {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}) {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username", username);
params.put("email", email);
params.put("password", password);
params.put("gender", gender);
return params;



/** Called when the user taps the Send button */
public void sendMessage(View view) {

// the request queue
queue = Volley.newRequestQueue(this);

// the parameters for the php
// map.put(KEY, VALUE);
map.put("name", "test");

// the JSON request
request = new JsonObjectRequest(
Request.Method.POST, // the request method
"http://myclassstudio.com/album/postjoson.php", // the URL
new JSONObject(map), // the parameters for the php
new Response.Listener<JSONObject>() { // the response listener
public void onResponse(JSONObject response){
// here you parse the json response
new Response.ErrorListener() { // the error listener
public void onErrorResponse(VolleyError error) {

/* here you can warn the user that there
was an error while trying to get the json
information from the php */

// executing the quere to get the json information






Completing Login Part

  • Come inside LoginActivity.java and write the following code.

Android Login and Registration Source Code Download

  • You can get my source code from below. You need to pay me a like, share or tweet to get the source code. The source code contains the Android Studio Project, PHP Files and Database File.


Buy and Download Full Tutorial and Source Code


Where can I find game assets?

Where can I find game assets?

FullStack Android Tutorial


Learning Java – Get a job as Android Developer

Where can I find game assets?

Where can I find game assets?

Be the first to comment

Leave a Reply