I have an app in which a user has 2 options, Sign in and Sign up. In the sign in option, the user enters his firebase username and password and goes to the MainActivity successfully.
In the Signup option, the user sees 4 screens simultaneously in which he/she is asked to enter some data about themselves. In the last screen, the user is asked for his email/username for firebase registration but for some reason, it gives an error when entering the data into firebase DB. And the most annoying thing is that android studio isn't even showing me the error.
Anyhow, the code is below. I have marked as a comment, "I think the main problem arises here." as a comment in my code. The flow is like this, it comes from RegScreen1 -> RegScreen2 -> RegScreen3 -> RegScreen4 -> MainActivity. But, for some reason, after RegScreen4 -> RegScreen3 appears.
Bundle b = getIntent().getExtras();
final String name = b.getString("name");
final String dob = b.getString("dob");
final String gender = b.getString("gender");
final String age = b.getString("age");
final String smoke = b.getString("smoke");
final String type = b.getString("type");
final String today = b.getString("today");
final String email = emailEditTextRegScreenFour.getText().toString();
final String password = passwordEditTextRegScreenFour.getText().toString();
if (email.contains("@") && email.contains(".com"))
{
Toast.makeText(RegistrationScreenFour.this, "@ and com available", Toast.LENGTH_SHORT).show();
Toast.makeText(RegistrationScreenFour.this, "email: " + email + "\npassword: " + password, Toast.LENGTH_SHORT).show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(RegistrationScreenFour.this, new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful())
{
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(PersonContract.Person.COL_SMOKER_NAME, name);
values.put(PersonContract.Person.COL_SMOKER_DOB, dob);
values.put(PersonContract.Person.COL_SMOKER_GENDER, gender);
values.put(PersonContract.Person.COL_SMOKER_AGE_STARTED_SMOKING, age);
values.put(PersonContract.Person.COL_SMOKER_SMOKES_IN_ONE_DAY, smoke);
values.put(PersonContract.Person.COL_SMOKER_SMOKE_ANY_TODAY, today);
values.put(PersonContract.Person.COL_SMOKER_USERNAME, email);
values.put(PersonContract.Person.COL_SMOKER_PASSWORD, password);
values.put(PersonContract.Person.COL_SMOKER_LAST_LOGIN, true);
//dbHelper.addSmokerEntry(values);
PersonDetails personDetails =
new PersonDetails(name, Integer.parseInt(age),
dob, gender, smoke, today, email, password, type);
// I think the main problem arises here.
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
DatabaseReference courseRef = database.getReference("PersonDetails");
courseRef.child(email).setValue(personDetails);
Toast.makeText(RegistrationScreenFour.this, "task successful", Toast.LENGTH_SHORT).show();
Intent i = new Intent(RegistrationScreenFour.this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}