package @Override protected void onStop() { super.onStop(); mAuth.removeAuthStateListener(firebaseAuthListener);

package com.example.hamza.hamari_sawari;import android.content.Intent;import android.support.annotation.NonNull;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.InputType;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.Toast;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.auth.AuthResult;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;import com.google.firebase.database.DatabaseReference;import com.google.firebase.database.FirebaseDatabase;public class DriverLoginActivity extends AppCompatActivity { private EditText mEmail, mPassword; private Button mLogin, mRegistration; private CheckBox mChk; private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener firebaseAuthListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_driver_login); mAuth = FirebaseAuth.getInstance(); firebaseAuthListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if(user!=null){ Intent intent = new Intent(DriverLoginActivity.this, DriverMapActivity.class); startActivity(intent); finish(); return; } } }; mChk = (CheckBox) findViewById(R.id.chk); mEmail = (EditText) findViewById(R.id.email); mPassword = (EditText) findViewById(R.id.password); mLogin = (Button) findViewById(R.id.login); mRegistration = (Button) findViewById(R.id.registration);mChk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b){ mPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { mPassword.setInputType(InputType.TYPE_CLASS_TEXT|InputType .TYPE_TEXT_VARIATION_PASSWORD); } }}); mRegistration.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String email = mEmail.getText().toString(); final String password = mPassword.getText().toString(); mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if(!task.isSuccessful()){ Toast.makeText(DriverLoginActivity.this, “sign up error”, Toast.LENGTH_SHORT).show(); }else{ String user_id = mAuth.getCurrentUser().getUid(); DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child(“Users”).child(“Drivers”).child(user_id).child(“name”); current_user_db.setValue(email); } } }); } }); mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String email = mEmail.getText().toString(); final String password = mPassword.getText().toString(); mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if(!task.isSuccessful()){ Toast.makeText(DriverLoginActivity.this, “sign in error”, Toast.LENGTH_SHORT).show(); } } }); } }); } @Override protected void onStart() { super.onStart(); mAuth.addAuthStateListener(firebaseAuthListener); } @Override protected void onStop() { super.onStop(); mAuth.removeAuthStateListener(firebaseAuthListener); }}