Ad

Infor/connection Return False Even Device Has Internet Connection

As the title, I am using infor/connection to check the connection from client to database but if I uninstall and reinstall app, the infor/connection return true and return false after that, even if the device can access the internet, I have tested on real and virtual device and this issue still remains.

this is the code for checking connect tion:



 mValueEventConnection = new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                boolean isConnected = dataSnapshot.getValue(Boolean.class);

                updateConnectionStatus(isConnected);

                Log.d("SSSSS-CONNECTION", isConnected + "");

            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Log.d("SSSSS-CONNECTION", databaseError + "");
            }
        };

        CONNECT_REF.addValueEventListener(mValueEventConnection);

and the result:

 D/SSSSS-CONNECTION: true
 D/SSSSS-CONNECTION: false

UPDATE:

After reinstall and open app the first time, the issue will occur, but the second time does not.

Ad

Answer

The .info/connection pseudo-node indicates whether the client has a connection to the Firebase Database server, which is more than just having a connection to the internet.

Note that the Firebase client automatically disconnects after a minute, if there is no active data listener and there are no writes. So if you have no active listeners or writes, and the disconnect happens about a minute or so after the connect, that could explain the behavior.

In that last case you can attach a listener to some regular part of your data, or some non-existing node: FirebaseDatabase.getInstance().getReference("ThisDoesNotExist").addValueEventListener(...).

Ad
source: stackoverflow.com
Ad