Firebase Authorization Error - android

I created a register activity with Firebase Authentication, but when I ran the application and clicked on the sign up button, nothing happened. Only the progress dialog, just rotating and it didn't even signup.
Here is my code:
public class RegisterActivity extends AppCompatActivity {
private EditText mNameField;
private EditText mEmailField;
private EditText mPasswordField;
private Button mRegisterBtn;
private FirebaseAuth mAuth;
private DatabaseReference mDatabase;
private ProgressDialog mProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users");
mProgress = new ProgressDialog(this);
mNameField = (EditText) findViewById(R.id.nameFied);
mEmailField = (EditText) findViewById(R.id.emailField);
mPasswordField = (EditText) findViewById(R.id.passwordField);
mRegisterBtn = (Button) findViewById(R.id.registerBtn);
mRegisterBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startRegister();
}
});
}
private void startRegister() {
final String name = mNameField.getText().toString().trim();
String email = mEmailField.getText().toString().trim();
String password = mPasswordField.getText().toString().trim();
if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)){
mProgress.setMessage("Signing up...please wait");
mProgress.show();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db = mDatabase.child(user_id);
current_user_db.child("name").setValue(name);
current_user_db.child("image").setValue("default");
mProgress.dismiss();
Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
}
}
});
}
if (TextUtils.isEmpty(name) && TextUtils.isEmpty(email) && TextUtils.isEmpty(password)){
Toast.makeText(RegisterActivity.this, "do not leave any field empty", Toast.LENGTH_LONG).show();
}
}
}
I don't know what I did wrong.
Here are my gradle dependencies:
compile 'com.google.firebase:firebase-database:9.2.0'
compile 'com.google.firebase:firebase-auth:9.2.0'

try to add a OnFailureListener to see what exception or error you are getting.
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db = mDatabase.child(user_id);
current_user_db.child("name").setValue(name);
current_user_db.child("image").setValue("default");
mProgress.dismiss();
Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.i("Firebase Exception -> ",e.getMessage());
}});

You are creating user with
createUserWithEmailAndPassword(email, password)
but you never sign-in. You also need to sign in after creating user with
signInWithEmailAndPassword(email, password)
and in that add data to your database.
And I would suggest to update your repository and decencies also.

Related

the firebase reference is not being added

for some reason, the data is not being added to the firebase database. maybe its because i set the database in test mode? i have no idea. this was working before, however today it stopped working.
private EditText EditTextFullName, EditTextAge, EditTextEmail, EditTextPassword;
private TextView registerUser;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
Objects.requireNonNull(getSupportActionBar()).hide();
EditTextFullName = (EditText) findViewById(R.id.fullName);
EditTextAge = (EditText) findViewById(R.id.age);
EditTextEmail = (EditText) findViewById(R.id.email);
EditTextPassword = (EditText) findViewById(R.id.password);
registerUser= (Button) findViewById(R.id.registerUser);
registerUser.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.registerUser:
registerUser();
break;
}
}
private void registerUser() {
String email = EditTextEmail.getText().toString().trim();
String age = EditTextAge.getText().toString().trim();
String fullname = EditTextFullName.getText().toString().trim();
String password = EditTextPassword.getText().toString().trim();
if(password.length() < 6) {
EditTextPassword.setError("Min password length should be 6 characters");
EditTextPassword.requestFocus();
return;
}
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
User user = new User(fullname, age, email);
FirebaseDatabase.getInstance().getReference("Users")
.child((FirebaseAuth.getInstance().getCurrentUser()).getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(Register.this, "User has been registered", Toast.LENGTH_LONG).show();
startActivity(new Intent(Register.this,Login.class));
} else
{
Toast.makeText(Register.this, "Failed to register", Toast.LENGTH_LONG).show();
}
};
});
}
}
});
}
}
Well it turns out that I completely flopped when writing my code. Turns out in my User class with my constructers, i had my strings there twice causing the database to not know what to use.

Unable to add user details on Firebase RealTime Database

I am currently trying to add user details who have registered in my app using Firebase Phone authentication to Firebase Real time database. I am successfully able to verify a user, but I am not able to send to Details Activity class where I need the user to enter his details, instead I jump to MainActivity Directly.
I do get Toast "Phone Verified" whenever I add a new user.
Register.java
public class Register extends AppCompatActivity {
FirebaseAuth auth;
String phoneNumber;
String otpCode;
String verificationId;
EditText phone, optEnter;
Button next;
CountryCodePicker countryCodePicker;
PhoneAuthCredential credential;
Boolean verificationOnProgress = false;
ProgressBar progressBar;
TextView state, resend;
PhoneAuthProvider.ForceResendingToken token;
//FirebaseFirestore fStore;
DatabaseReference reference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
phone = findViewById(R.id.phone);
optEnter = findViewById(R.id.codeEnter);
countryCodePicker = findViewById(R.id.ccp);
next = findViewById(R.id.nextBtn);
auth = FirebaseAuth.getInstance();
progressBar = findViewById(R.id.progressBar);
state = findViewById(R.id.state);
resend = findViewById(R.id.resendOtpBtn);
resend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// todo:: resend OTP
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!phone.getText().toString().isEmpty() && phone.getText().toString().length() == 10) {
if (!verificationOnProgress) {
next.setEnabled(false);
progressBar.setVisibility(View.VISIBLE);
state.setVisibility(View.VISIBLE);
String phoneNum = "+" + countryCodePicker.getSelectedCountryCode() + phone.getText().toString();
Log.d("phone", "Phone No.: " + phoneNum);
requestPhoneAuth(phoneNum);
} else {
next.setEnabled(false);
optEnter.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
state.setText("Logging in");
state.setVisibility(View.VISIBLE);
otpCode = optEnter.getText().toString();
if (otpCode.isEmpty()) {
optEnter.setError("Required");
return;
}
credential = PhoneAuthProvider.getCredential(verificationId, otpCode);
verifyAuth(credential);
}
} else {
phone.setError("Valid Phone Required");
}
}
});
}
private void requestPhoneAuth(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber, 60L, TimeUnit.SECONDS, this,
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onCodeAutoRetrievalTimeOut(String s) {
super.onCodeAutoRetrievalTimeOut(s);
Toast.makeText(Register.this, "OTP Timeout, Please Re-generate the OTP Again.", Toast.LENGTH_SHORT).show();
resend.setVisibility(View.VISIBLE);
}
#Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationId = s;
token = forceResendingToken;
verificationOnProgress = true;
progressBar.setVisibility(View.GONE);
state.setVisibility(View.GONE);
next.setText("Verify");
next.setEnabled(true);
optEnter.setVisibility(View.VISIBLE);
}
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
verifyAuth(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(Register.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void verifyAuth(PhoneAuthCredential credential) {
auth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(Register.this, "Phone Verified", Toast.LENGTH_SHORT).show();
checkUserProfile();
} else {
progressBar.setVisibility(View.GONE);
state.setVisibility(View.GONE);
Toast.makeText(Register.this, "Can not Verify phone and Create Account.", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
protected void onStart() {
super.onStart();
if (auth.getCurrentUser() != null) {
progressBar.setVisibility(View.VISIBLE);
state.setText("Logging IN");
state.setVisibility(View.VISIBLE);
checkUserProfile();
}
}
private void checkUserProfile() {
FirebaseUser firebaseUser = auth.getCurrentUser();
assert firebaseUser != null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
if (userid != null) {
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(Register.this, "Profile doesnt exist", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, Details.class);
startActivity(intent);
}
}
}
Details.java
public class Details extends AppCompatActivity {
public static final String TAG = "TAG";
EditText firstName,lastName,email;
Button saveBtn;
FirebaseAuth auth;
FirebaseFirestore fStore;
String userID;
DatabaseReference reference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
firstName = findViewById(R.id.firstName);
lastName = findViewById(R.id.lastName);
email = findViewById(R.id.emailAddress);
saveBtn = findViewById(R.id.saveBtn);
auth = FirebaseAuth.getInstance();
fStore = FirebaseFirestore.getInstance();
saveBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String First_Name= firstName.getText().toString();
String Last_Name= lastName.getText().toString();
String EMail= email.getText().toString();
if(firstName.getText().toString().isEmpty()||lastName.getText().toString().isEmpty() || email.getText().toString().isEmpty()){
Toast.makeText(Details.this, "Fill the required Details", Toast.LENGTH_SHORT).show();
return;
}
register(First_Name,Last_Name,EMail);
}
});
}
private void register(String first_name, String last_name, String eMail) {
FirebaseUser firebaseUser = auth.getCurrentUser();
assert firebaseUser != null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
Map<String,Object> hashmap=new HashMap<>();
hashmap.put("First Name",first_name);
hashmap.put("Last Name",last_name);
hashmap.put("Email-Id",eMail);
reference.setValue(hashmap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Intent intent=new Intent(Details.this,MainActivity.class);
startActivity(intent);
}
else{
Toast.makeText(Details.this,"Registration failed...",Toast.LENGTH_SHORT).show();
}
}
});
}
}
It seems that in your Register class in checkUserProfile() function you are checking if userId from firebaseUser.getUid() is not null. At the moment this will always be not null, because you are already asserting that the user must be authenticated at this point.
Judging from your code this is just a mistake on your part. I assume that what you are trying to do is actually see if the details already exist in the FirebaseDatabase. You have a reference to the database which you are not using.
private void checkUserProfile() {
FirebaseUser firebaseUser = auth.getCurrentUser();
assert firebaseUser != null;
String userid = firebaseUser.getUid();
//Unused reference
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
if (userid != null) {
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
}
But also my question would be, are you sure you want to use Realtime Database for user details? You are saving details in Details function using FirebaseFirestore. Didn't you want to check if the details already exist in FirebaseFirestore?
How to fix:
First, let's create the user data class:
public class User {
public String uid;
public String firstName;
public String lastName;
public String email;
public User {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public User(String uid, String firstName, String lastName, String email) {
this.uid = uid;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
}
Now, let's change the code in Details.java class to use User class:
private void register(String first_name, String last_name, String eMail) {
FirebaseUser firebaseUser = auth.getCurrentUser();
assert firebaseUser != null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
User user = new User(userid, firstName, lastName, eMail)
reference.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Intent intent=new Intent(Details.this,MainActivity.class);
startActivity(intent);
}
else{
Toast.makeText(Details.this,"Registration failed...",Toast.LENGTH_SHORT).show();
}
}
});
}
Let's check if the registration details exist in the database in checkUserProfile() method:
private void checkUserProfile() {
FirebaseUser firebaseUser = auth.getCurrentUser();
assert firebaseUser != null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
reference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
}
else {
Toast.makeText(Register.this, "Profile doesnt exist", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, Details.class);
startActivity(intent);
}
}
#Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
});
}
Let me know if it works for you.
Firebase will generate a single unique key(UID) on registration of account whether using Email/Phone number. This key remains associated with that account until the account exists in the firebase authentication list.
So, once you register with some number/email at that time UID is created for the same. every time you fetch UID it will return that user UID, and you are also asserting Firebase User is NotNull So, every time you got UID from firebase and app move to the dashboard screen.
If you want to move users to a Detail screen then. You can also add a condition based on firebase User.
if(firebaseUser != null){
// Get UID and Move to Dashboard
}else{
// Move to Detail Screen
}

Firebase doesn't register new users

I have a problem, I can't register in my chat app. It shows me that "You can't register". I don't know where is the problem. I set read and write to true in my database but it still not working. I use the last versions of Firebase. I haven't problems with the internet and connected firebase to my project successfully.
This is my register activity
MaterialEditText username, email, password;
Button btn_register;
FirebaseAuth auth;
DatabaseReference reference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Регистрация");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
username = findViewById(R.id.username);
email = findViewById(R.id.email);
password = findViewById(R.id.password);
btn_register = findViewById(R.id.btn_register);
auth = FirebaseAuth.getInstance();
btn_register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String txt_username = username.getText().toString();
String txt_email = email.getText().toString();
String txt_password = password.getText().toString();
if (TextUtils.isEmpty(txt_username) || TextUtils.isEmpty(txt_email) || TextUtils.isEmpty(txt_password)) {
Toast.makeText(RegisterActivity.this, "Write more", Toast.LENGTH_SHORT).show();
} else if (txt_password.length() < 6 ){
Toast.makeText(RegisterActivity.this, "Password too short ", Toast.LENGTH_SHORT).show();
} else {
register(txt_username, txt_email, txt_password);
}
}
});
}
private void register(final String username, String email, String password){
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
FirebaseUser firebaseUser= auth.getCurrentUser();
assert firebaseUser !=null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
HashMap<String, String> HashMap = new HashMap<>();
HashMap.put("id", userid);
HashMap.put("username", username);
HashMap.put("imageURL", "default");
reference.setValue(HashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
}
});
}else {
Toast.makeText(RegisterActivity.this, "You cant register", Toast.LENGTH_SHORT).show();
}
}
});
}
}
When initializing your FirebaseDatabase reference, the item node with the provided user id does not exist yet in your database thus the reference is null
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
Instead, initialize the reference to the Users node
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users");
Then when saving the user's data you can save to their userId:
reference.child(userid).setValue(HashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
...
});
in manifest file allow internet permission. if you continue this err create failure listener and print failure code
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();

Registeration with firebase authentication

I have created a registration form with firebase auth. The gradle build runs just fine. But when i run the app, its says myapp has stopped working.
With email and password authentication, i want to enter user info like phone number and car plate no (as it is car park app)
public class RegisterScreen extends AppCompatActivity {
private EditText emailet;
private EditText password2et;
private EditText phonenoet;
private EditText carplatenoet;
Button register2btn;
ProgressDialog mProgressDialog;
private FirebaseAuth mAuth;
private DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_screen);
emailet = (EditText) findViewById(R.id.emailet);
password2et = (EditText) findViewById(R.id.password2et);
phonenoet = (EditText) findViewById(R.id.phonenoet);
carplatenoet = (EditText) findViewById(R.id.carplatenoet);
register2btn = (Button) findViewById(R.id.register2btn);
mProgressDialog = new ProgressDialog(this);
mAuth = FirebaseAuth.getInstance();
register2btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String email = emailet.getText().toString().trim();
String password = password2et.getText().toString().trim();
String phoneno = phonenoet.getText().toString().trim();
String carplateno = carplatenoet.getText().toString().trim();
if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password) && !TextUtils.isEmpty(phoneno) && !TextUtils.isEmpty(carplateno)) {
mProgressDialog.setTitle("Loading...");
mProgressDialog.setMessage("Please Wait");
mProgressDialog.setCanceledOnTouchOutside(true);
mProgressDialog.show();
register(email, password, phoneno, carplateno);
}
}
public void register(final String email, final String password, final String phoneno, final String carplateno) {
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users").child(uid);
HashMap<String, String> userMap = new HashMap<>();
userMap.put("Email", email);
userMap.put("Password", password);
userMap.put("PhoneNo", phoneno);
userMap.put("CarPlateNo", carplateno);
mDatabase.setValue(userMap).addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Intent intent = new Intent(RegisterScreen.this, MainNavigationActivity.class);
startActivity(intent);
}
});
}
}
});
}
});
}
}

Firebase Auth not working in Async Task

I am using Firebase Auth (registering a new user) , it worked perfectly on the Main Thread but when i moved it to the background , Authentication always failed .
Here is the the method for creating a new user :
public void createAccount(String email, String password) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
// 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(registerActivity.this, "bad",
Toast.LENGTH_SHORT).show();
sr = false;
} else {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
EditText etname = (EditText) findViewById(R.id.etName);
EditText etlname = (EditText) findViewById(R.id.etLName);
String namez = etname.getText().toString();
String lnamez = etlname.getText().toString();
DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReference();
Toast.makeText(registerActivity.this, "good", Toast.LENGTH_SHORT).show();
String UID = user.getUid();
mDatabase.child("users").child(UID + "_lname").setValue(lnamez);
mDatabase.child("users").child(UID + "_name").setValue(namez);
sr = true;
}
}
// ...
}
});
}
and here is the AsyncTask :
private class createInBack extends AsyncTask<Void, Void, Void> {
//Executes the 'createAccount' method in background .
EditText etemail = (EditText) findViewById(R.id.etEmail);
EditText etpassword = (EditText) findViewById(R.id.etPassword);
String email = etemail.getText().toString();
String password = etpassword.getText().toString();
#Override
protected void onPreExecute() {
super.onPreExecute();
spinner.setVisibility(View.VISIBLE);
}
#Override
protected Void doInBackground(Void... voids) {
createAccount(email, password);
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if(sr){
Toast.makeText(registerActivity.this, "we good here", Toast.LENGTH_SHORT).show();
startActivity(new Intent(registerActivity.this, MainActivity.class));
}
spinner.setVisibility(View.GONE);
}
}
so what is the problem ?
Problem Solved ,
I found in the XML layout that i forgot to remove the "android:onClick" from the button.
Linxy is right, it is not necessary to make an Asynctask for your goal.
Firebase solves that for you, look at a simple example.
private void loginAccount(String email, String password) {
final ProgressDialog progressDialog = new ProgressDialog(Login.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(false);
progressDialog.setMessage("Autenticando...");
progressDialog.show();
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
login.setEnabled(true);//button-ignore
login.setAlpha(1f);
if (task.isSuccessful()){
progressDialog.dismiss();
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
//Toast.makeText(Login.this,"Sesion iniciada",Toast.LENGTH_SHORT).show();
}else{
progressDialog.dismiss();
Toast.makeText(Login.this,"Email or password invalidate",Toast.LENGTH_SHORT).show();
Log.i("sesion","MaldatosH2");
}
}
});
}
To create a user is the same xd

Categories

Resources