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); } } }); 
4
  • 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. Commented Dec 9, 2021 at 17:07
  • Are you looking for stackoverflow.com/questions/46798981/…? Commented Dec 9, 2021 at 17:08
  • is there java version? Commented Dec 9, 2021 at 17:18
  • Converting from Swift calls to the Firestore API to Java versions should be pretty easy if you keep the documentation handy: 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. Commented Dec 9, 2021 at 19:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.