0

I am facing an issue during calling reference.addValueEventListener() of Firebase if internet is Disconnect.

Not any one function is called on Internet Disconnection. How i can identify my firebase request is failed due to Internet Disconnection.

notification_Reference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }

    })

Thanks

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Sheharyar Ejaz
  • 2,808
  • 1
  • 14
  • 15

1 Answers1

1

With just the listener alone, you can't detect lack of connection. The Firebase SDK automatically retries the connection until it succeeds. The only way the listen fails is if the server has told the client that it will not be able to access the data. This is helpful for mobile client that go online and offline frequently. You don't have to write any of the code to retry.

What you can do is use another listener to detect the connection status. See also:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441