I am writing an application in which you need to log in, and then go to another page. I enter the data into the fields, click the log in button and the transition to another page does not occur. The application crashes
I use the firebase database in the application
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginemail = (EditText) findViewById(R.id.email);
loginpassword = (EditText) findViewById(R.id.password);
generatorBtn = (Button) findViewById(R.id.idBtnGenerator);
RegistrationBtn = (Button) findViewById(R.id.register);
generatorBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!validateEmail() | !validatePassword()) {
return;
} else if(validateEmail() && validatePassword()) {
checkUser();
} else {
Toast.makeText(getApplicationContext(), "Успешно", Toast.LENGTH_SHORT).show();
Intent i = new Intent(ActivityLogin.this, GeneratorQRcodeActivity.class);
startActivity(i);
}
}
});
RegistrationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ActivityLogin.this,
RegistrationActivity.class);
startActivity(i);
}
});
}
public Boolean validateEmail() {
String val = loginemail.getText().toString();
if (val.isEmpty()) {
loginemail.setError("Адрес электронной почты не заполнен");
return false;
} else {
loginemail.setError(null);
return true;
}
}
public Boolean validatePassword() {
String val = loginpassword.getText().toString();
if (val.isEmpty()) {
loginpassword.setError("Пароль не заполнен");
return false;
} else {
loginpassword.setError(null);
return true;
}
}
public void checkUser() {
String userLoginEmail =
loginemail.getText().toString().trim();
String userPassword = loginpassword.getText().toString().trim();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("users");
Query checkUserDatabase = reference.orderByChild("email").equalTo(userLoginEmail);
checkUserDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
loginemail.setError(null);
String passwordFromDB = snapshot.child(userLoginEmail).child("password").getValue(String.class);
if (!Objects.equals(passwordFromDB, userPassword)) {
loginemail.setError(null);
} else {
loginpassword.setError("Недопустимая форма учетной записи");
loginpassword.requestFocus();
}
} else {
loginemail.setError("Пользователь не существует");
loginemail.requestFocus();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
I tried different loop transformations, the application crashes anyway
generatorBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!validateEmail() | !validatePassword()) {
return;
} else if(validateEmail() && validatePassword()) {
checkUser();
} else {
Toast.makeText(getApplicationContext(), "Успешно", Toast.LENGTH_SHORT).show();
Intent i = new Intent(ActivityLogin.this, GeneratorQRcodeActivity.class);
startActivity(i);
}
}
});
The error is in this block, but I don't understand why
logcat: 2024-03-12 15:10:56.877 1699-7807 WindowManager system_server E win=Window{e2fc2f4 u0 com.example.scannerandgenerator/com.example.scannerandgenerator.RegistrationActivity} destroySurfaces: appStopped=true cleanupOnResume=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.ActivityRecord.destroySurfaces:6862 com.android.server.wm.ActivityRecord.destroySurfaces:6843 com.android.server.wm.ActivityRecord.activityStopped:7510 com.android.server.wm.ActivityClientController.activityStopped:310 android.app.I
You have to first connect your project to the Firebase project and then
Enable Email/Password in Authentication Section
Use the below code for the LOGIN through Firebase. (change below code with requirements)
Register Code
UserInformation.java