user3879781
user3879781

Reputation: 83

Firebase not removing eventlistener using 'gdx-fireapp'

I'm trying to implement Firebase in a LibGdx app using gdx-fireapp library. I can read, change or remove any data successfully, but when I try to remove an event listener after getting the data that I want it does not get removed. I'm supposed to call cancel(); for this to happen, but nothing happens. I've even tried calling cancel(); multiple times but it still doesn't work. is anyone familiar with how can I fix this?

Here is how I call it

        GdxFIRDatabase.inst()
                .inReference("Rooms/")
                .onDataChange(Map.class)
                .then(new Consumer<Map>() {
                    @Override
                    public void accept(Map map) {
                        Gdx.app.log("test","onDataChangedCalled");
                    }
                });

And here is how I cancel it:

        GdxFIRDatabase.inst().inReference("Rooms/").onDataChange(Map.class).cancel();

After cancel(); is called it is supposed on stopping logging "onDataChangedCalled" when the value changes but it doesn't.

Upvotes: 0

Views: 47

Answers (1)

user3879781
user3879781

Reputation: 83

For anyone that faces the same problem, you have to store the listener to a variable and use this variable to call it and cancel it.

Here is how I did it:

    ListenerPromise<Map> Rooms;

        Rooms = GdxFIRDatabase.inst().inReference("Rooms/").onDataChange(Map.class);

        GdxFIRDatabase.promise()
                .then(Rooms)
                .then(new Consumer<Map>() {
                    @Override
                    public void accept(Map map) {
                        Gdx.app.log("test","onDataChangedCalled");
                    }
                });

and to cancel it just call cancel(); like this:

Rooms.cancel();

Upvotes: 1

Related Questions