如何将用户从注册活动重定向到主活动?



我想将用户重定向到' loginactivity ';当他点击"创建账户"按钮时但它做不到,需要帮助!
点击"CreateAccount"按钮一次没有发生任何事情,但第二次Toast显示已经有一个用户具有相同的电子邮件地址,并且在我的数据库中该用户已注册,无法找出任何问题。

//register activity
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.HashMap;
import java.util.Objects;
public class RegisterActivity extends AppCompatActivity {
private EditText FullName, UserName, EmailAdress, Password,ConfirmPassword;
private DatabaseReference Mrootref;
private FirebaseAuth Mauth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
FullName=findViewById(R.id.FullName);
UserName=findViewById(R.id.UserName);
EmailAdress=findViewById(R.id.EmailAddress);
Password=findViewById(R.id.Password);
ConfirmPassword=findViewById(R.id.ConfirmPassword);
Button createAccount = findViewById(R.id.CreateAccount);
TextView logtxt = findViewById(R.id.blogin);
//        Database Reference
Mrootref=FirebaseDatabase.getInstance().getReference();
Mauth=FirebaseAuth.getInstance();

createAccount.setOnClickListener(view -> {
String txtFullName=FullName.getText().toString();
String txtUserName=UserName.getText().toString();
String txtEmailAdress=EmailAdress.getText().toString();
String txtPassword=Password.getText().toString();
String txtConfirmPassword=ConfirmPassword.getText().toString();
if(TextUtils.isEmpty(txtFullName)||TextUtils.isEmpty(txtUserName)||TextUtils.isEmpty(txtEmailAdress)||TextUtils.isEmpty(txtPassword)||TextUtils.isEmpty(txtConfirmPassword)) {
Toast.makeText(RegisterActivity.this, "You have missed something", Toast.LENGTH_SHORT).show();
}else if (txtPassword.length() <= 7) {
Toast.makeText(RegisterActivity.this, "The Password must have atleast 8 character", Toast.LENGTH_SHORT).show();
}else if(!txtPassword.equals(txtConfirmPassword)) {
Toast.makeText(RegisterActivity.this, "The Password You Entered is not same check it again", Toast.LENGTH_SHORT).show();
}else{
registerUser(txtFullName, txtUserName, txtEmailAdress, txtPassword);
}
});

logtxt.setOnClickListener(view -> startActivity(new Intent(RegisterActivity.this,LoginActivity.class)));
//        Removeable Lines
TextView skip = findViewById(R.id.skip);
skip.setOnClickListener(view -> {
Intent hmActivity = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(hmActivity);
});
}
public void registerUser(final String FullName, final String UserName, final String EmailAdress, final String Password){
Mauth.createUserWithEmailAndPassword(EmailAdress, Password).addOnSuccessListener(authResult -> {
HashMap<String, Object> map=new HashMap<>();
map.put("fullname", FullName);
map.put("username", UserName);
map.put("emailadress", EmailAdress);
map.put("id", Objects.requireNonNull(Mauth.getCurrentUser()).getUid());
Mrootref.child("Users").child(Mauth.getCurrentUser().getUid()).setValue(map).addOnCompleteListener(task -> {
if (task.isSuccessful()){
Intent intent=new Intent(RegisterActivity.this, LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
Log.d("RegisterActivity", "User registration completed");
Toast.makeText(RegisterActivity.this, "Welcome to DreamOway!", Toast.LENGTH_SHORT).show();
Log.d("RegisterActivity", "Starting MainActivity");
startActivity(intent);
finish();
}
});
}).addOnFailureListener(e -> {
Log.d("RegisterActivity", "Error in database operation: " + e.getMessage());
});
}
}
app level gradle build 
`plugins {
id 'com.android.application' id 'com.google.gms.google-services'
}
android {
namespace 'com.example.dreamoway' compileSdk 33
defaultConfig {
applicationId "com.example.dreamoway"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.google.firebase:firebase-database:20.1.0'
implementation 'com.google.firebase:firebase-auth:21.2.0'
implementation 'com.google.firebase:firebase-bom:31.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}`

//project level gradle.build

`buildscript { dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
} plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false }`

createAccount视图没有启动活动,因为您定义了logtxt视图来启动活动。您需要将startActivity调用移动到createAccount上的侦听器中,以使其按照您所描述的方式工作。