java - Firebase Android method to check existence of user's profile info in Firebase database -


i don't error message want execute code differently.

if check following java code, runs tag:1 > tag:2 > tag:4 > tag:5 > tag:3. want run tag:1 > tag:2 > tag:3 > tag:4 > tag:5.

basically, want check user's profile exist or not before starting of new activity. looking method check existence of child in firebase database. not changing data database. so, should not ondatachange() method. think, there once() method available in old firebase same. there method available?

thank you

 log.i("tag:","1");      string userid = getuid();      log.i("tag:","2");        databasereference.child("users").child(userid).addlistenerforsinglevalueevent(new valueeventlistener() {                 @override                 public void ondatachange(datasnapshot datasnapshot) {                      userprofile userprofile = datasnapshot.getvalue(userprofile.class);                      log.i("tag:","3");                                     if (userprofile == null){                         //do                      } else {                         //do                     }                 }                  @override                 public void oncancelled(databaseerror databaseerror) {                  }             });      log.i("tag:","4");     log.i("tag:","5"); 

from can see code is:

  • you have userid of userprofile
  • you checking whether profile exists on specific id or no.

well, creating object , checking whether null or no 1 way but firebase has pre-defined method checking whether data exists on specific node or no:

datasnapshot.exists()

returns true if datasnapshot contains data. more efficient using snapshot.val() !== null.

this official docs mention.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -