I followed the API documentation for setting up user authentication. My registerActivity correctly sends data to the Firebase database but when I try to set up the sign in authentication for my loginActivity, the login button does not go to the mainActivity as I expect it to. Is there something wrong with my user sign in set up or maybe there is another way I should be using intent for the login button?
public class LoginActivity extends AppCompatActivity {
private EditText emailField;
private EditText passwordField;
private Button loginButton;
private FirebaseAuth loginAuth;
private FirebaseAuth.AuthStateListener loginAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login3);
loginAuth = FirebaseAuth.getInstance();
emailField = (EditText) findViewById(R.id.emailField);
passwordField = (EditText) findViewById(R.id.passwordField);
loginButton = (Button) findViewById(R.id.loginButton);
final TextView RegisterLink = (TextView) findViewById(R.id.registerLink);
loginAuthListener = new FirebaseAuth.AuthStateListener(){
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth){
if(firebaseAuth.getCurrentUser() != null){
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
}
};
RegisterLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
loginButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
startSignIn();
}
});
}
#Override
protected void onStart(){
super.onStart();
loginAuth.addAuthStateListener(loginAuthListener);
}
private void startSignIn(){
String email = emailField.getText().toString();
String password = passwordField.getText().toString();
if(TextUtils.isEmpty(email) || TextUtils.isEmpty(password)){
if(TextUtils.isEmpty(email)){
Toast.makeText(LoginActivity.this, "Email Field is Empty", Toast.LENGTH_LONG).show();
}else if(TextUtils.isEmpty(password)){
Toast.makeText(LoginActivity.this, "Password Field is Empty", Toast.LENGTH_LONG).show();
} else{
Toast.makeText(LoginActivity.this, "Email Field and Password Field are Empty", Toast.LENGTH_LONG).show();
}
} else {
loginAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(LoginActivity.this,"Either the Password or Email Field is Incorrect. Please Try Again.", Toast.LENGTH_LONG).show();
}
}
});
}
}
}
I looked at the log console while running the app and found that the version of google services the emulator was running on was not up to date. To fix the problem, you can either...
Run the app on a real android device
Make sure you're using the same version of all your dependencies (all are 9.8, all are 10.0.0, and so on)
Be sure to click "sync project with gradle files" in your android tool list
Related
hello I'm making a login in my project and when I try to input the data it says email address is badly formatted
Codes
public class MainActivity extends AppCompatActivity {
private EditText email;
private EditText Password;
private ImageButton BackMenu;
private TextView SignIn;
private Button login;
ProgressBar progressBar;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
email = (EditText)findViewById(R.id.log_email);
Password = (EditText)findViewById(R.id.password);
BackMenu = (ImageButton)findViewById(R.id.returnMenu);
SignIn = (TextView) findViewById(R.id.reg_SignIn);
login = (Button)findViewById(R.id.btn_Login);
auth = FirebaseAuth.getInstance();
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loginUser();
}
});
SignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
registrationForm();
progressBar.setVisibility(View.VISIBLE);
}
});
BackMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openShopMenu();
progressBar.setVisibility(View.VISIBLE);
}
});
}
private void loginUser() {
String userEmail = email.getText().toString().trim();
String userPass = Password.getText().toString().trim();
progressBar.setVisibility(View.VISIBLE);
if (TextUtils.isEmpty(userEmail)){
Toast.makeText(this, "Email is empty", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
return;
}
if (TextUtils.isEmpty(userPass)){
Toast.makeText(this, "Password is empty", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
return;
}
if (userPass.length() < 5){
Toast.makeText(this, "Password must be 5 characters or more", Toast.LENGTH_SHORT).show();
}
auth.signInWithEmailAndPassword(userPass,userEmail)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(MainActivity.this, "Login is Successful", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
else {
Toast.makeText(MainActivity.this, "Error"+task.getException(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
public void openShopMenu() {
Intent intent = new Intent(MainActivity.this, ShopMenu.class);
startActivity(intent);
progressBar.setVisibility(View.GONE);
}
public void registrationForm(){
Intent intent = new Intent(MainActivity.this,Registration.class);
startActivity(intent);
progressBar.setVisibility(View.GONE);
}
}
Problem
the input is:
Email : gon#gmail.com
Password : 12345678
The user fails to login and the message below pops out
The email address is badly formatted
and I don't think there's a problem in my .xml file
android:inputType="textEmailAddress"
I am trying to keep the user logged into my chat app even after they close the app. So the only way they will be logged out of their account is if they click the log out button.
So far the user does stayed logged in but when I click the log out button, the app crashes. This is the error I get
Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
at com.example.chatterbox.ChatsFragment.onCreateView(ChatsFragment.java:54)
the problem is that that error is from a different file. Can someone please help me ?
public class LoginActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private ProgressDialog loadingBar;
private Button LoginButton ;
private EditText UserEmail, UserPassword;
private TextView NeedNewAccountLink, ForgetPasswordLink;
private DatabaseReference UsersRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
RelativeLayout relativeLayout = findViewById(R.id.layout);
AnimationDrawable animationDrawable = (AnimationDrawable) relativeLayout.getBackground();
animationDrawable.setEnterFadeDuration(5000);
animationDrawable.setExitFadeDuration(5000);
animationDrawable.start();
mAuth = FirebaseAuth.getInstance();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
InitializeFields();
if (UsersRef != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
NeedNewAccountLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SendUserToRegisterActivity();
}
});
LoginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AllowUserToLogin();
}
});
}
private void AllowUserToLogin () {
String email = UserEmail.getText().toString();
String password = UserPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please enter your email", Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "Please enter your password", Toast.LENGTH_SHORT).show();
} else {
loadingBar.setTitle("Logging In");
loadingBar.setMessage("Please wait...");
loadingBar.setCanceledOnTouchOutside(true);
loadingBar.show();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
String currentUserId = mAuth.getCurrentUser().getUid();
String deviceToken = FirebaseInstanceId.getInstance().getToken();
UsersRef.child(currentUserId).child("device_token")
.setValue(deviceToken)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
SendUserToMainActivity();
Toast.makeText(LoginActivity.this, "Logged in successfully", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
} else {
String message = task.getException().toString();
Toast.makeText(LoginActivity.this, "Error:" + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
private void InitializeFields () {
LoginButton = (Button) findViewById(R.id.login_button);
UserEmail = (EditText) findViewById(R.id.login_email);
UserPassword = (EditText) findViewById(R.id.login_password);
NeedNewAccountLink = (TextView) findViewById(R.id.need_new_account_link);
ForgetPasswordLink = (TextView) findViewById(R.id.forget_password_link);
loadingBar = new ProgressDialog(this);
}
private void SendUserToMainActivity () {
Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
private void SendUserToRegisterActivity () {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(registerIntent);
}
Error line :
currentUserID = mAuth.getCurrentUser().getUid();
This is how I check if the user is logged in. If they are I send them to the MainActivity. If they are not they stay on the LoginActivity
if (UsersRef != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
You call
mAuth = FirebaseAuth.getInstance();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
and then
if (UsersRef != null) {
//do something
}
It's a bit odd because you need to know if there's currently a valid user logged in Firebase. This snippet maybe can be useful:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// User is signed in
} else {
// No user is signed in
}
But you're checking if the variable UsersRef (that is a DatabaseReference, i guess) is null or not... Indeed you just gived it a value!!!
Use addOnSuccessListener instead of addOnCompleteListener
auth.signInWithEmailAndPassword(mEmail, mPassword)
.addOnSuccessListener(LoginActivity.this, new OnSuccessListener<AuthResult>(){
#Override
public void onsuccess(#NonNull AuthResult authResult){
//your code goes here
}
});
I have an error which says:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.pc.proyectofinal.SignUp.onCreate(SignUp.java:46)
I tried two ways:
First with:
Intent SignUpINTENT = new Intent(SignUp.this, ResetPassword.class);
startActivity(SignUpINTENT);
And the second time with:
startActivity(new Intent(SignUp.this, ResetPassword.class));
Both give me the same error.
Here is the code:
public class SignUp extends AppCompatActivity {
private EditText inputEmail, inputPassword; //hit option + enter if you on mac , for windows hit ctrl + enter
private Button btnSignIn, btnSignUp, btnResetPassword;
private ProgressBar progressBar;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_signup);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
btnSignIn = (Button) findViewById(R.id.sign_in_button);
btnSignUp = (Button) findViewById(R.id.sign_up_button);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnResetPassword = (Button) findViewById(R.id.btn_reset_password);
btnResetPassword.setOnClickListener(new View.OnClickListener() { //here is the problem with the regist
#Override
public void onClick(View v) {
Intent SignUpINTENT = new Intent(SignUp.this, ResetPassword.class);
startActivity(SignUpINTENT);
//startActivity(new Intent(SignUp.this, ResetPassword.class));
}
});
btnSignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
btnSignUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
if (password.length() < 6) {
Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignUp.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Toast.makeText(SignUp.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignUp.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(SignUp.this, Main.class));
finish();
}
}
});
}
});
}
#Override
protected void onResume() {
super.onResume();
progressBar.setVisibility(View.GONE);
}
}
You have this line in onCreate() commented:
setContentView(R.layout.activity_signup);
Why?
Without this line there is no layout inflated for the activity and all the views can't be found by findViewById and they are null.
So when you try
btnResetPassword.setOnClickListener()
you get
java.lang.NullPointerException
Hello im trying to create a firebase logging in auth with 2 different users, the admin, and user. but like when i was trying to log in, The application would crash. Heres the error i think
my database
and here is my code on the login
public class LoginActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth auth;
private ProgressBar progressBar;
private Button btnSignup, btnLogin, btnReset;
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.mipmap.ic_launcher);
auth = FirebaseAuth.getInstance();
setContentView(R.layout.activity_login);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnSignup = (Button) findViewById(R.id.btn_signup);
btnLogin = (Button) findViewById(R.id.btn_login);
btnReset = (Button) findViewById(R.id.btn_reset_password);
//db
mFirebaseInstance = FirebaseDatabase.getInstance();
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
btnSignup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, signup.class));
}
});
btnReset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, ResetPasswordActivity.class));
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressBar.setVisibility(View.GONE);
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
inputPassword.setError(getString(R.string.minimum_password));
} else {
Toast.makeText(LoginActivity.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
onAuthSuccess(task.getResult().getUser());
}
}
private void onAuthSuccess(FirebaseUser user) {
if (user !=null){
mFirebaseDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(user.getUid()).child("type");
mFirebaseDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
if(Integer.parseInt(value) == 1) {
startActivity(new Intent(LoginActivity.this, UserActivity.class));
Toast.makeText(LoginActivity.this, "Welcome User", Toast.LENGTH_SHORT).show();
finish();
}else {
startActivity(new Intent(LoginActivity.this, AdminActivity.class));
Toast.makeText(LoginActivity.this, "Welcome", Toast.LENGTH_SHORT).show();
finish();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
});
}
});
}
I feel like the problem lies on the ondata change one but I don't know what to do to fix this, so im asking for your help :O
Try this:
mFirebaseDatabase = FirebaseDatabase.getInstance().getReference().child("Accounts").child("Users").child(user.getUid());
mFirebaseDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.child("type").getValue(String.class);
if(Integer.parseInt(value) == 1) {
startActivity(new Intent(LoginActivity.this, UserActivity.class));
Toast.makeText(LoginActivity.this, "Welcome User", Toast.LENGTH_SHORT).show();
finish();
}else {
startActivity(new Intent(LoginActivity.this, AdminActivity.class));
Toast.makeText(LoginActivity.this, "Welcome", Toast.LENGTH_SHORT).show();
finish();
}
}
try the above, have the reference at the userid then inside onDataChange retrieve the type. you need to reference in order and specify the child name like this:
String value = dataSnapshot.child("type").getValue(String.class);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm having an issue with
FirebaseAuth.signInWithEmailAndPassword(email, password)
I'm getting the error message
non-static method 'signInWithEmailAndPassword(java.lang.string, java.lang.string)' cannot be referenced from a static context.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button loginButton;
private EditText username;
private EditText passwordLogin;
private TextView signUpText;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() != null){
finish();
startActivity(new Intent(getApplicationContext(), dashBoard.class));
}
progressDialog = new ProgressDialog(this);
username = (EditText) findViewById(R.id.username);
passwordLogin = (EditText) findViewById(R.id.passwordLogin);
loginButton = (Button) findViewById(R.id.loginButton);
signUpText = (TextView) findViewById(R.id.signUpText);
loginButton.setOnClickListener(this);
signUpText.setOnClickListener(this);
}
private void userLogin(){
String email = username.getText().toString().trim();
String password = passwordLogin.getText().toString().trim();
if (TextUtils.isEmpty(email)){
//username is empty
Toast.makeText(this, "Please enter username", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)){
//password is empty
Toast.makeText(this, "Please enter your password", Toast.LENGTH_SHORT).show();
}
progressDialog.setMessage("Logging in user");
progressDialog.show();
FirebaseAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
Intent intent= new Intent(MainActivity.this,dashBoard.class);
startActivity(intent); }
}
});
}
#Override
public void onClick(View view) {
if ( view == loginButton){
userLogin();
}
if(view == signUpText) {
startActivity(new Intent(this, userRegistration.class));
}
}
}
You are trying to access a member function(non static) from a static context that is why it is giving to that error. For using that method, you first have to create an instance of FirebaseAuth and then call the signInWithEmailAndPassword method from that object.
FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener() {
#Override
public void onComplete(#NonNull Task task) {
//your callback method will go here
}
});
you should access that method using the Object "firebaseAuth" that you have already created. And also it looks from error that signInWithEmailAndPassword() is anon-static method, so it can not be accessed directly using class name. Check the code below and replace it.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button loginButton;
private EditText username;
private EditText passwordLogin;
private TextView signUpText;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() != null){
finish();
startActivity(new Intent(getApplicationContext(), dashBoard.class));
}
progressDialog = new ProgressDialog(this);
username = (EditText) findViewById(R.id.username);
passwordLogin = (EditText) findViewById(R.id.passwordLogin);
loginButton = (Button) findViewById(R.id.loginButton);
signUpText = (TextView) findViewById(R.id.signUpText);
loginButton.setOnClickListener(this);
signUpText.setOnClickListener(this);
}
private void userLogin(){
String email = username.getText().toString().trim();
String password = passwordLogin.getText().toString().trim();
if (TextUtils.isEmpty(email)){
//username is empty
Toast.makeText(this, "Please enter username", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)){
//password is empty
Toast.makeText(this, "Please enter your password", Toast.LENGTH_SHORT).show();
}
progressDialog.setMessage("Logging in user");
progressDialog.show();
firebaseAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
Intent intent= new Intent(MainActivity.this,dashBoard.class);
startActivity(intent); }
}
});
}
#Override
public void onClick(View view) {
if ( view == loginButton){
userLogin();
}
if(view == signUpText) {
startActivity(new Intent(this, userRegistration.class));
}
}
}
You are trying to access non-static (member) function from static context. Hence the error.
private final FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithEmailAndPassword("email_here", "password_here").addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
// If authentication is successful, you receive callback here.
// You can get uId (userId) of the logged in user as..
String userId = authResult.getUser().getUid();
}
});