我有3种类型的用户。在使用Realtime
Firebase Database
我已经尝试过使用Firebase
身份验证,并且已经成功为单个用户登录,但是我希望三个不同用户在3个活动中都可以使用它。
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();
String USER_TYPE_1 = "student";
String USER_TYPE_2 = "teacher";
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)
您如何在onClick方法中放置条件以检查用户是老师还是学生。喜欢:
if(userType.equals(UserType_1)){
//Call intent for Student's Activity
}
if(userType.equals(UserType_2)){
// Call intent for Teacher's Activity
}
确保为不同的用户创建了三个不同的活动。
尽管我建议您在主活动和三个不同的片段上创建。它将使您的应用程序更轻。 希望这可以帮助。