Click here to Skip to main content
15,665,394 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1 You have to design 2 screens. 
a) Registration screen 
b) Dashboard screen 

2) Registration screen should contain below fields: 
a) First Name 
b) Last Name 
c) Email 
d) Mobile Number 
e) Password 
f) Confirm Password

3) Registration Form should have standard validation like:

a) User can enter max 50 characters for First Name 
b) User can enter max 100 characters for Last Name 
c) Email standard validation (xx@xx.xx) 
d) Password should be in hidden 
e) Users can enter max 20 characters for Passwords. 

4) Registration screen records should be inserted into the Firebase Realtime Database. 

5) After submitting a record on the Registration screen, the user should redirect to the Dashboard screen. 

6) On Dashboard Screen, Get all the users data from database and display list of users.

I have done the authentication is working fine but not showing in realtime database.

What I have tried:

Package com.example.registration;

import androidx.annotation.NonNull;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

            private EditText  edfname,edlname,edemail,edpassword,edcpassword,edphone;
            private Button btregister;

            FirebaseAuth fAuth;

        // creating a variable for our
        // Firebase Database.
        FirebaseDatabase firebaseDatabase;

        // creating a variable for our Database
        // Reference for Firebase.
        DatabaseReference databaseReference;

        // creating a variable for
        // our object class

        RegisterInfo registerInfo;

protected void onCreate(Bundle savedInstanceState) {

        // initializing our edittext and button
        edfname = findViewById(;
        edlname = findViewById(;
        edemail = findViewById(;
        edpassword = findViewById(;
        edcpassword = findViewById(;
        edphone = findViewById(;

        // below line is used to get the
        // instance of our FIrebase database.
        firebaseDatabase = FirebaseDatabase.getInstance();

        // below line is used to get reference for our database.
        databaseReference = firebaseDatabase.getReference("RegisterInfo");

        // initializing our object
        // class variable.
        registerInfo = new RegisterInfo();

        btregister = findViewById(;

        // adding on click listener for our button.
        btregister.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

        // getting text from our edittext fields.
        String fname = edfname.getText().toString().trim();
        String lname = edlname.getText().toString().trim();
        String email= edemail.getText().toString().trim();
        String password = edpassword.getText().toString().trim();
        String cpassword = edcpassword.getText().toString().trim();
        String phone = edphone.getText().toString().trim();

        fAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                public void onComplete(@NonNull Task<AuthResult> task) {

                                Toast.makeText(MainActivity.this, "User created", Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(getApplicationContext(),Dashboard.class));
                                Toast.makeText(MainActivity.this, "Error !" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();


        // below line is for checking weather the
        // edittext fields are empty or not.
        if (TextUtils.isEmpty(fname) && TextUtils.isEmpty(lname) && TextUtils.isEmpty(email) && TextUtils.isEmpty(password) && TextUtils.isEmpty(cpassword)&& TextUtils.isEmpty(phone) ) {
        // if the text fields are empty
        // then show the below message.
        Toast.makeText(MainActivity.this, "Please add some data.", Toast.LENGTH_SHORT).show();
        } else {
        // else call the method to add
        // data to our database.

private void addDatatoFirebase(String fname, String lname, String email,String password, String cpassword, String phone) {
        // below 3 lines of code is used to set
        // data in our object class.

        // we are use add value event listener method
        // which is called with database reference.
        databaseReference.addValueEventListener(new ValueEventListener() {

public void onDataChange(@NonNull DataSnapshot snapshot) {
        // inside the method of on Data change we are setting
        // our object class to our database reference.
        // data base reference will sends data to firebase.

        // after adding this data we are showing toast message.
        Toast.makeText(MainActivity.this, "data added", Toast.LENGTH_SHORT).show();

public void onCancelled(@NonNull DatabaseError error) {
        // if the data is not added or it is cancelled then
        // we are displaying a failure toast message.
        Toast.makeText(MainActivity.this, "Fail to add data " + error, Toast.LENGTH_SHORT).show();
Richard Deeming 10-Jan-22 4:49am    
You seem to have forgotten to ask a question.

However, you do appear to be storing passwords in plain text, which is a major security problem:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

And you seem to be storing both the "password" and "confirm password" values, which is pointless - your code should be validating that those two values are identical, so there's no point storing it twice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900