Is there a way to implement a Firebase server-side countdown timer in Android Studio?
I want the timer to be server side, meaning that whenever a user opens my app the counter will always be at the same time for all users.
I read the answers to this question, but they're 2+ years old and Firebase changed a lot since. It was acquired by Google in October 2014 and a significant number of new features were featured in May 2016 at Google I/O.
If Firebase can't provide that feature, is there another platform that can provide server-side countdown?
Create a server side timer that updates a value in your realtime database.
Firebase ref = new Firebase('/firebase/database/url/time');
new AnimationTimer(){
start(){...}
stop(){...}
handle(){...ref.addValue(time);}
};
That will update your real-time database every millisecond. To see it in your application just call it.
Firebase ref = new Firebase('/firebase/database/url/time/value')
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot ds) {
Platform.runLater(() -> {
label.setText(ds.getValue() + "");
});
}
@Override
public void onCancelled(FirebaseError fe) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
It will update in real-time on your application in milliseconds. I was able to get this running in Java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With