Implementing a Firebase Server Countdown Timer for Android?

Is there a way to implement a Firebase server countdown timer in Android Studio?

I want the timer to be server-side, which means that whenever a user opens my application, the counter will always be at the same time for all users.

I read the answers to this question, but they are 2+ years old, and Firebase has changed a lot since then. It was acquired by Google in October 2014, and a significant number of new features were introduced in May 2016 on Google I / O.

If Firebase cannot provide this feature, is there another platform that can provide server-side countdowns?

+4
source share
2 answers

I have no better idea for a countdown, only count on customers.

What happens if you do this:

  • Get server time in timestamp (add to variable srvTime)

Create a new record for the countdown timer:

  • Start time: srvTime
  • End time: Time in ms when countdown endede.g. (5min = 60,000 * 5)

And you can count on the client side.

Or create a listener forServerValue.TIMESTAMP

ref.addValueEventListener(new ValueEventListener() {
    public void onDataChange(DataSnapshot dataSnapshot) {
        System.out.println(dataSnapshot.getValue()); 
    }

    public void onCancelled(DatabaseError databaseError) { }
});
ref.setValue(ServerValue.TIMESTAMP);
0
source

Create a server-side timer that updates the value in your database in real time.

Firebase ref = new Firebase('/firebase/database/url/time');
    new AnimationTimer(){
        start(){...}
        stop(){...}
        handle(){...ref.addValue(time);}
        };

This will update your database in real time every milliseconds. To see this in your application, just call him.

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.
        }

    });

. Java

+1

All Articles