Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java firebase syncrhonous data read

// create a java.util.concurrent.Semaphore with 0 initial permits
final Semaphore semaphore = new Semaphore(0);

// attach a value listener to a Firebase reference
ref.addValueEventListener(new ValueEventListener() {
    // onDataChange will execute when the current value loaded and whenever it changes
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        // TODO: do whatever you need to do with the dataSnapshot

        // tell the caller that we're done
        semaphore.release();
    }

    @Override
    public void onCancelled(FirebaseError firebaseError) {

    }
});

// wait until the onDataChange callback has released the semaphore
semaphore.acquire();

// send our response message
ref.push().setValue("Oh really? Here is what I think of that");
Comment

PREVIOUS NEXT
Code Example
Java :: Service vs IntentService. 
Java :: Is the main method compulsory in Java? 
Java :: android java how to stop users fromgoing back too much 
Java :: int to integer array in java 
Java :: how to call the main method in java 
Java :: Method Overloading by changing the data type of parameters Java 
Java :: android sqlite insert or replace 
Java :: https://graph.instagram.com/14.0/10218560180051171 
Java :: natural log in java 
Java :: show menuitem when menu hovered javafx 
Java :: jbutton actionperformed 
Java :: Write a Java Program to check if any number is a magic number or not. 
Java :: android adb is using too much cpu 
Java :: ex: java loop 
Java :: how to accept only numbers and whitespace in java 
Java :: zoom sdk not initialized 
Java :: javacal 
Java :: sysout is not working in eclipse 
Java :: ejercicios de clases abstractas e interfaces en java 
Java :: netbeans how to get string from jcombobox 
Java :: .throwFor in java 
Java :: find maximum number of rides in amusement park python 
Java :: open youtube by default in full landscape mode pragmatically 
Java :: The root directory of the External Storage on every android version 
Java :: while(++i<5)f*=i;System.out.println(f); 
Java :: sorted hashmap java 
Java :: java.lang.noclassdeffounderror even though class is present 
Java :: bukkit shutdown 
Java :: Share Icon/Button 
Java :: Meditation for stress and depression 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =