I'm new to FireStore and I'm building an app for a educational institute. I have 2 different batches and each batch with 2 different classes. {CBSE > xi, xii & CHSE > xi, xii}
I want the student to login to my app with FirebaseAuth and FireStore already have those students data as
User(collection) >> users(Document)(using the userID given by FirebaseAuth) >> FullName: (Student's name)
Phone:(number)
Board:(There Batch or Board, i.e., CBSE or CHSE)
Class:(class, i.e., XI or XII)
email:(email)
so if a student belongs to CBSE and XI, I want them to go to a different activity and if from XII of the same batch then go to a different activity. Similarly for the other Batch (CHSE) also.
I have written a code check this out
public class test extends AppCompatActivity {
FirebaseAuth fauth;
FirebaseFirestore fstore;
String userID, mboard, mclass;
TextView Board, Class;
private Object testB, testC;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maths);
Board = findViewById(R.id.Board);
Class = findViewById(R.id.Class);
fauth = FirebaseAuth.getInstance();
fstore = FirebaseFirestore.getInstance();
userID = fauth.getCurrentUser().getUid();
final DocumentReference documentReference = fstore.collection("users").document(userID);
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
Board.setText(documentSnapshot.getString("Board"));
Class.setText(documentSnapshot.getString("Class"));
mboard = Board.toString();
mclass = Class.toString();
testB = String.valueOf(documentSnapshot.getData().get(Board));
testC = String.valueOf(documentSnapshot.getData().get(Class));
if (testB == "CHSE") {
if (testC == "XI") {
startActivity(new Intent(new Intent(getApplicationContext(),MainActivity.class)));
}
if (testC == "XII") {
startActivity(new Intent(new Intent(getApplicationContext(),test.class)));
}
}
}
});
}
}
From a YouTube tutorial I got this but with 2 problems :- 1. I have to use a textView on the layout. How can I just store the value to a variable??? 2. the if...else doesn't work. I just want that to happen. How will I let students go to there respected activities with there Batch and Class????
Please help me out and thank's in advance....