Reputation: 49
public class MainActivity extends AppCompatActivity {
private EditText email,password,repassword,name;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();// removes app title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.nameid);
email = (EditText) findViewById(R.id.emailid);
password = (EditText) findViewById(R.id.passwordid);
mDatabase=FirebaseDatabase.getInstance().getReference().child("users");
mAuth = FirebaseAuth.getInstance();
}
public void signUpButtonClicked(View view){
if (!TextUtils.isEmpty(email.getText().toString())&&!TextUtils.isEmpty(password.getText().toString())&& !TextUtils.isEmpty(name.getText().toString())){
Toasty.error(MainActivity.this, "This is an error toast.", Toast.LENGTH_SHORT, true).show();
}
else {
final ProgressDialog spinner = new ProgressDialog(MainActivity.this);
spinner.setMessage("Please wait...");
spinner.show();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//check if already user phone
if (dataSnapshot.child(email.getText().toString()).exists()) {
spinner.dismiss();
Toasty.warning(MainActivity.this,"Sorry User registered",Toast.LENGTH_SHORT, true).show();
} else {
spinner.dismiss();
users User = new users(name.getText().toString(), password.getText().toString(), email.getText().toString());
mDatabase.child(email.getText().toString()).setValue(User);
Toast.makeText(MainActivity.this, "Signup Succesful !", Toast.LENGTH_SHORT).show();
Intent loginIntent = new Intent(MainActivity.this, Login.class);
startActivity(loginIntent);
finish();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
public void loginClicked( View view){
Intent startloging = new Intent(MainActivity.this,Login.class);
startActivity(startloging);
}
}
public class Login extends AppCompatActivity {
private EditText userEmail,userPassword;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();// removes app title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
setContentView(R.layout.activity_login);
userEmail = (EditText) findViewById(R.id.emailid);
userPassword = (EditText) findViewById(R.id.passwordid);
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users");
}
public void signUpButtonClicked(View view){
Intent signup = new Intent(Login.this,MainActivity.class);
startActivity(signup);
}
public void loginButttonClicked(View view) {
if (userPassword.getText().toString().isEmpty()|userEmail.getText().toString().isEmpty()){
Toast.makeText(this, "Please fill all!!", Toast.LENGTH_SHORT).show();
}
else {
final ProgressDialog spinner = new ProgressDialog(Login.this);
spinner.setMessage("Please wait...");
spinner.show();
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child(userEmail.getText().toString()).exists()) {
spinner.dismiss();
users User = dataSnapshot.child(userEmail.getText().toString()).getValue(users.class);
Common.currentuser = User;
mDatabase.removeEventListener(this);
if (User.getPassword().equals(userPassword.getText().toString())) {
Intent menuIntent = new Intent(Login.this, Menu.class);
startActivity(menuIntent);
finish();
Toasty.success(Login.this, "Signin Successful", Toast.LENGTH_SHORT, true).show();
} else {
spinner.dismiss();
Toast.makeText(Login.this, "Signin Failed", Toast.LENGTH_SHORT).show();
}
} else {
spinner.dismiss();
Toast.makeText(Login.this, "User does not exist", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
}
So my App was working fine on debug mode, then i decided to build a signed apk to send to my friends so they could check it out. When they tried it, the app would not login, not because the credentials are wrong, but it was because it failed to start the next intent (Toast: "Signin Successful" shows up); so instead of starting the next intent it takes me back to the sign-up activity intent( by the way sign-up activity is my first page when you start the app).
The confusing part was it was working fine on my phone (btw i Run from android studio to test on my phone ) the i decided to install the Released apk i sent to my friends. After that my app started behaving exactly as it did on their phones. (not starting the next intent after successful login).. now i tried reinstalling the debug apk and my app still behaves the same..
Now my app works completely different and it from this(MainActivity) that if any of the fields is empty it should Toast "This is an error toast." but instead it say "Sorry User registered". It also does something similar when you fill all the fields and click create new account it give a Toast that says "This is an error toast." instead of "Sorry User registered" or "Signup Succesful !"
Upvotes: 1
Views: 146
Reputation: 26
The reason why it is showing the toast This is an error toast
because in your if
condition where you are checking for if the text boxes are empty or not. There might be a logical issue at TextUtils.isEmpty()
which returns true if text fields are empty, try using - TextUtils.isEmpty(string) || TextUtils.isEmpty(string1)|| TextUtils.isEmpty(string2)
.
I hope it may help you.
Upvotes: 1