Coders Packet

How to Create a Registration Page using Java with Firebase Connectivity

By Akshay Kumar

A Registration page (also known as a Sign-up page) . The source code is about How to Create a Registration Page using Java with Firebase Connectivity. This was developed using java

                                                       Registration Page

Through this program, I have to Create a Registration Page using Java with Firebase Connectivity. Through this registration page user easily fields the data. A registration form is a list of fields that a user will input data into or submit to an individual. This servlet class receives all the data entered by the user and stores an into the real-time database in firebase. here I have performed the real-time database logic but you may separate it.

package com.example.instagram;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.util.HashMap;

public class RegisterActivity extends AppCompatActivity {

EditText username, email, password,phone;
Button register;
TextView textView;
private ProgressDialog pd;
private DatabaseReference reference;
FirebaseAuth auth;





@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
username = findViewById(R.id.NameR);
email = findViewById(R.id.EmailAddressR);
password = findViewById(R.id.PasswordR);
register = findViewById(R.id.Register1);
phone=findViewById(R.id.PhoneR);
textView = findViewById(R.id.textViewR);

reference=FirebaseDatabase.getInstance().getReference();
auth=FirebaseAuth.getInstance();
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

pd = new ProgressDialog(RegisterActivity.this);
pd.setMessage("Please Wait.....");
pd.show();

String str_username = username.getText().toString();
String str_phone=phone.getText().toString();
String str_email = email.getText().toString();
String str_password = password.getText().toString();

if (TextUtils.isEmpty(str_username) || TextUtils.isEmpty(str_email) ||TextUtils.isEmpty(str_phone)|| TextUtils.isEmpty(str_password)) {

Toast.makeText(RegisterActivity.this, "All Fields are Required ", Toast.LENGTH_SHORT).show();
} else if (str_password.length() < 6) {
Toast.makeText(RegisterActivity.this, "Password must have 6 character", Toast.LENGTH_SHORT).show();
} else {

register(str_username,str_phone,str_email,str_password);

}


}
});

}

private void register(final String username,final String phone, final String email,final String password) {

auth.createUserWithEmailAndPassword(email,password).addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(AuthResult authResult) {

HashMap<String,Object>map=new HashMap<>();
map.put("username",username);
map.put("phone",phone);
map.put("email",email);
map.put("password",password);
map.put("imageurl","https://firebasestorage.googleapis.com/v0/b/instagramapp-b8128.appspot.com/o/placeholder.png?alt=media&token=f736fc59-5eb8-455d-83a1-bd27176c606f");
map.put("id",auth.getCurrentUser().getUid());
map.put("bio","");
reference.child("Users").child(auth.getCurrentUser().getUid()).setValue(map).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
pd.dismiss();
Toast.makeText(RegisterActivity.this, "Register Successfully", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(RegisterActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

finish();


}
}
});




}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
pd.dismiss();
Toast.makeText(RegisterActivity.this,e.getMessage(), Toast.LENGTH_SHORT).show();
}
});

}


}


 

Output-1

Registration page

 

Output-2

firebase

Download project

Reviews Report

Submitted by Akshay Kumar (akshaykumar)

Download packets of source code on Coders Packet