im am doing my project for studies on android app developing and i have a problem with getting currentUser that is logged in and showing he's name on TextView. it seems that it is always showing me the last user that was created no matter with which user i login
this is the java file:
public class ActionsFragment extends Fragment {
FirebaseAuth auth;
Button acManagmentBtn;
TextView tvName;
public ActionsFragment() {
// Required empty public constructor
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
DatabaseReference managerRef = reference.child("Users").child("Manager");
managerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
reference.child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Manager manager = ds.getValue(Manager.class);
tvName.setText(manager.getName());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
// Toast.makeText(getActivity(), "Null שם פרטי", Toast.LENGTH_SHORT).show();
}
});
auth = FirebaseAuth.getInstance();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_actions, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
tvName = view.findViewById(R.id.tv_name);
acManagmentBtn = view.findViewById(R.id.manage_ac_btn);
acManagmentBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AcManagmentActivity.class);
startActivity(intent);
}
});
}
}
and this is the tree in my firebase realtime database:
thank you for helping!