Here I am adding the snippet where I am successfully retrieve data from firebase and use it as in my textview inside onDataChange() function but when I try to use it outside this function then it's not working and also I dont want to bring TOOLBAR inside onDataChange Function cause I have other places too where I need to use the data.
DatabaseReference databaseReference = firebaseDatabase.getReference(firebaseAuth.getUid());
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
UserProfile userProfile = dataSnapshot.getValue(UserProfile.class);
//profileName.setText(userProfile.getName());
pasteName = userProfile.getName();
pasteEmail = userProfile.getEmail();
testCase.setText(pasteName);//THIS IS WORKING
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(LoggedIn.this,"Problem Fetching Data",Toast.LENGTH_SHORT).show();
}
});
toolbar = (Toolbar)findViewById(R.id.toolbarMain);
toolbar.setTitle(pasteName);//NOT WORKING