0

i develop app with java and firestore. i want to show user on my app randomly so i need to userId i wrote this code but not working randomly. how can i do randomly ?

my firestore

public class MainMenu extends AppCompatActivity {
 
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_menu);           
            FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser();
            String currentid=user.getUid();
            DocumentReference reference;
            FirebaseFirestore firestore=FirebaseFirestore.getInstance();
    
            reference=firestore.collection("Users").document(currentid);
    
            reference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                    if(task.getResult().exists()){
                        DocumentSnapshot document= task.getResult();
                        String nameResult=task.getResult().getString("name");
                        String ageResult=task.getResult().getString("age");
                        String url=task.getResult().getString("profile_photo");
                        String eMail=task.getResult().getString("email");
    
                        List<String> hobbiesResult=(List<String>) document.get("Hobbies");
    
                        Map<String, Object> map = document.getData();
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            if (entry.getKey().equals("Hobbies")) {
                              Log.d("TAG", entry.getValue().toString());
                              hobbies.setText(entry.getValue().toString());
    
                            }
                        }
                        Picasso.get().load(url).into(imageView);
                        name.setText(nameResult);
                        mail.setText(eMail);
                        age.setText(ageResult);
                    }
                }
            });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
habudaney
  • 9
  • 5
  • The Firebase Realtime Database and Cloud Firestore are two separate databases. Please only mark your question with the relevant tag, not with both. Also: I don't see anything related to Cloud Functions in the question, so removed that tag too. – Frank van Puffelen Dec 09 '21 at 17:07
  • Are you looking for https://stackoverflow.com/questions/46798981/firestore-how-to-get-random-documents-in-a-collection? – Frank van Puffelen Dec 09 '21 at 17:08
  • is there java version? – habudaney Dec 09 '21 at 17:18
  • Converting from Swift calls to the Firestore API to Java versions should be pretty easy if you keep the documentation handy: https://firebase.google.com/docs/firestore/query-data/queries. If you're struggling with a specific conversion, I recommend opening a new question for just that with its own [minimal repro](http://stackoverflow.com/help/mcve). – Frank van Puffelen Dec 09 '21 at 19:08

0 Answers0