Skip to content Skip to sidebar Skip to footer

How To Redirect To Different Pages Based On Firebase Information

Firebase Structure For my project, I would like to allow users to login to respective homepages based on their identity (eg: Buyer,Seller) after clicking a button with the firebase

Solution 1:

@Danial check this code

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference("users");
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot snapshot) {
        for (DataSnapshot dataSnapshot:snapshot.getChildren()){
            String mail=dataSnapshot.child("type").getValue().toString();
             if (userType.equals("Buyer")) {
          startActivity(new Intent(MainActivity.this,BuyerHomepage.class));
                              }
                            if(userType.equals("Seller")) {
           startActivity(new Intent(MainActivity.this,SellerHomepage.class));
                              }
        }
  
    }

    @Override
    public void onCancelled(@NonNull DatabaseError error) {

    }
});

Post a Comment for "How To Redirect To Different Pages Based On Firebase Information"