Skip to content

Instantly share code, notes, and snippets.

View navinkumar0118's full-sized avatar

Navinkumar navinkumar0118

  • Chennai
View GitHub Profile
@navinkumar0118
navinkumar0118 / activity_registration.xml
Created February 6, 2019 10:23
Firebase_Authentication_Blog
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
tools:context=".RegistrationActivity">
<TextView
package com.navinprojects.myfirebaseauth;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity">
<TextView
package com.navinprojects.myfirebaseauth;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
package com.navinprojects.myfirebaseauth;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser == null){
//if No user signed in, it will direct to Login activity
Intent intent = new Intent(DashboardActivity.this,LoginActivity.class);
startActivity(intent);
finish();
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="logout"
android:id="@+id/logout"/>
</menu>
//This method will create new User on firebase console...
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// SignUp in success, Direct to the dashboard Page...
Toast.makeText(RegistrationActivity.this, "Authentication Successfully completed", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(intent);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ffc107</color>
<color name="colorPrimaryDark">#ffa000</color>
<color name="colorAccent">#D81B60</color>
</resources>
FirebaseAuth.getInstance().signOut();