如果我使用用户类型登录,则应该打开该用户类型活动,如果使用其他用户,则应该打开其他用户类型活动。这意味着我要在使用特定用户类型进行身份验证时打开三个不同的活动。
附加的数据库映像:
package com.example.studentcoordinator;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.LoginFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
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;
public class Login_Form extends AppCompatActivity {
EditText txtEmail, txtPassword;
Button btn_login;
ProgressDialog progressDialog;
RadioGroup radioGroup;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login__form);
getSupportActionBar().setTitle("Login Page");
txtEmail = (EditText) findViewById(R.id.signinemail);
txtPassword = (EditText) findViewById(R.id.signinpassword);
btn_login = (Button) findViewById(R.id.loginbutton);
firebaseAuth = FirebaseAuth.getInstance();
radioGroup = findViewById(R.id.radiogroup);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = txtEmail.getText().toString().trim();
String password = txtPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(Login_Form.this, "Please Enter Valid Email", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(Login_Form.this, "Please Enter Valid Password", Toast.LENGTH_SHORT).show();
return;
}
if (password.length() < 6) {
Toast.makeText(Login_Form.this, "Password Too Short", Toast.LENGTH_SHORT).show();
return;
}
displayloader();
firebaseAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(Login_Form.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(Login_Form.this, Coordinator_homepage.class);
progressDialog.dismiss();
startActivity(intent);
} else {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Login Failed Or User Not Available", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
public void displayloader() {
progressDialog = new ProgressDialog(Login_Form.this);
progressDialog.setMessage("Logging .. Please Wait !!");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.show();
}
}
答案 0 :(得分:0)
您只需为此使用开关盒
switch (role) {
case "Teacher":
Intent intent = new Intent(HomeActivity.this , TeacherActivity.class);
startActivity(intent);
break;
case "Student":
Intent intent = new Intent(HomeActivity.this , StudentActivity.class);
startActivity(intent);
break;
case "Coordinator":
Intent intent = new Intent(HomeActivity.this , CoordinatorActivity.class);
startActivity(intent);
break;
}