I created a firebased DB and have a login screen but my login screen doesn't seem to do anything I can see in Logcat that nothing is happening when I put details in and click the Login button any help in what I am doing wrong here. code below for MainActivity and xml file.
package com.example.firebaseintro;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
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.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class MainActivity extends AppCompatActivity {
private FirebaseDatabase database;
private DatabaseReference databaseReference;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListner;
private static final String TAG = "MainActivity";
private EditText email;
private EditText password;
private Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email = (EditText) findViewById(R.id.emailED);
password = (EditText) findViewById(R.id.passwordED);
login = (Button) findViewById(R.id.loginButton);
mAuth = FirebaseAuth.getInstance();
database = FirebaseDatabase.getInstance();
databaseReference = database.getReference("message");
databaseReference.setValue("another World");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
Toast.makeText(MainActivity.this, value, Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
mAuthListner = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user !=null) {
//User is Signed in
Log.d(TAG, "User Signed In");
}else {
//User is Signed Out
Log.d(TAG, "User Signed Out");
}
}
};
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String emailString = email.getText().toString();
String pwd = password.getText().toString();
if (emailString.equals("") && !pwd.equals("")){
mAuth.signInWithEmailAndPassword(emailString, pwd)
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Failed Sign In", Toast.LENGTH_LONG)
.show();
}else {
Toast.makeText(MainActivity.this, "Signed In!!", Toast.LENGTH_LONG)
.show();
databaseReference.setValue("Hey I am Working");
}
}
});
}
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListner);
}
@Override
protected void onStop() {
super.onStop();
if (mAuthListner !=null){
mAuth.removeAuthStateListener(mAuthListner);
}
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/emailED"
android:layout_width="327dp"
android:layout_height="39dp"
android:ems="10"
android:hint="@string/email"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.064"
android:autofillHints="" />
<EditText
android:id="@+id/passwordED"
android:layout_width="325dp"
android:layout_height="52dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailED"
app:layout_constraintVertical_bias="0.06" />
<Button
android:id="@+id/loginButton"
android:layout_width="284dp"
android:layout_height="61dp"
android:layout_marginTop="28dp"
android:text="@string/login"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordED" />
</androidx.constraintlayout.widget.ConstraintLayout>
12-13 13:25:05.453 11690-11690/? I/art: Not late-enabling -Xcheck:jni (already on)
12-13 13:25:05.618 11690-11690/com.example.firebaseintro W/System: ClassLoader referenced unknown path: /data/app/com.example.firebaseintro-1/lib/x86
12-13 13:25:05.738 11690-11690/com.example.firebaseintro I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
12-13 13:25:05.767 11690-11690/com.example.firebaseintro I/FirebaseInitProvider: FirebaseApp initialization successful
12-13 13:25:06.088 11690-11690/com.example.firebaseintro W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-13 13:25:06.153 11690-11716/com.example.firebaseintro I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to fallback implementation
12-13 13:25:06.603 11690-11722/com.example.firebaseintro D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-13 13:25:06.648 11690-11690/com.example.firebaseintro D/MainActivity: User Signed Out
12-13 13:25:06.719 11690-11722/com.example.firebaseintro I/OpenGLRenderer: Initialized EGL, version 1.4
12-13 13:25:06.719 11690-11722/com.example.firebaseintro W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
12-13 13:25:06.744 11690-11722/com.example.firebaseintro D/EGL_emulation: eglCreateContext: 0xae424780: maj 3 min 1 rcv 4
12-13 13:25:06.750 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:06.754 11690-11722/com.example.firebaseintro E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
12-13 13:25:06.754 11690-11722/com.example.firebaseintro E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
12-13 13:25:06.755 11690-11722/com.example.firebaseintro E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
12-13 13:25:07.221 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:07.844 11690-11690/com.example.firebaseintro I/Choreographer: Skipped 68 frames! The application may be doing too much work on its main thread.
12-13 13:25:08.185 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:08.228 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:08.247 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:08.338 11690-11722/com.example.firebaseintro V/RenderScript: 0xa12c9000 Launching thread(s), CPUs 2
12-13 13:25:08.725 11690-11722/com.example.firebaseintro D/EGL_emulation: eglMakeCurrent: 0xae424780: ver 3 1 (tinfo 0xae43e4f0)
12-13 13:25:10.169 11690-11722/com.example.firebaseintro E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaaa8b2c0