0
I’m trying to register using Firebase. Everything is correct there in Firebase, but when I click on Register in the APP, nothing happens, it seems that the button is without function.
Can someone help me?
package com.towerapps.thetower.soulchat;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
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;
public class RegisterActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private Toolbar mToolbar;
private ProgressDialog loadingBar;
private EditText RegisterUserName;
private EditText RegisterUserEmail;
private EditText RegisterUserSenha;
private Button CriarContaButton;
private FirebaseAuth.AuthStateListener firebaseAuthStateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user !=null){
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);
finish();
return;
}
}
};
mToolbar = (Toolbar) findViewById(R.id.register_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Login");
mToolbar = (Toolbar) findViewById(R.id.login_toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
RegisterUserName = (EditText) findViewById(R.id.register_nome);
RegisterUserEmail = (EditText) findViewById(R.id.register_email);
RegisterUserSenha = (EditText) findViewById(R.id.register_senha);
CriarContaButton = (Button) findViewById(R.id.criar_conta_button);
loadingBar = new ProgressDialog(this);
CriarContaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nome = RegisterUserName.getText().toString();
String email = RegisterUserEmail.getText().toString();
String senha = RegisterUserSenha.getText().toString();
CriarConta(nome, email, senha);
}
});
}
private void CriarConta(String nome, String email, String senha) {
if (TextUtils.isEmpty(nome)){
Toast.makeText(RegisterActivity.this, "Digite seu nome.",
Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(email)){
Toast.makeText(RegisterActivity.this, "Digite seu email.",
Toast.LENGTH_LONG).show();
if (TextUtils.isEmpty(senha)){
Toast.makeText(RegisterActivity.this, "Digite sua senha.",
Toast.LENGTH_LONG).show();
}
else {
loadingBar.setTitle("Criar nova conta");
loadingBar.setMessage("Aguarde, enquanto estamos criando uma conta para você");
loadingBar.show();
mAuth.createUserWithEmailAndPassword(email, senha)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
else
{
Toast.makeText(RegisterActivity.this, "Ocorreu um erro, tente novamente...", Toast.LENGTH_SHORT).show();
}
loadingBar.dismiss();
}
});
}
}
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthStateListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthStateListener);
}
}
Use the debugger to identify where the execution is going. It has very little information to give you an answer.
– Pablo Almeida
the error is this, https://www.facebook.com/100007208682235/videos/vb.100007208682235/1910826789167592/? type=2&theater¬if_t=video_processed¬if_id=1509063351499642, I don’t know if this video helps much but...
– Yuri Sousa
Yuri, it would be much more productive for us if you used the debugger to tell us where your code is going, what the values of variables etc. You can’t figure out the mistake just by looking at this video-- it could be a million things.
– Pablo Almeida
if square bracket (Textutils.isEmpty(email)){ ... }
– Itapox