You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/06/06 09:10:40 UTC

[GitHub] [cordova-plugin-network-information] PieterVanPoyer edited a comment on issue #110: bug: 'onConnect' does not work as expected

PieterVanPoyer edited a comment on issue #110:
URL: https://github.com/apache/cordova-plugin-network-information/issues/110#issuecomment-640016840


   Hey
   
   I did check the Android code and found something interesting.
   
   On next lines, there is a check on the equality of the network state before and after a change.
   The code seems to try to send an update only after a change. But this code goes long way back.
   
   https://github.com/apache/cordova-plugin-network-information/blob/9f8527062776ead04982d7fab12875a66bf69855/src/android/NetworkManager.java#L221-L233
   
   The thisInfo and lastInfo are JSONObjects.
   
   _But when I run following code in a testproject. 2 JSONObjects with the same values are not seen as equal._
   
   ```
   try {
               JSONObject connectionInfo = new JSONObject();
               connectionInfo.put("type", "myType");
               connectionInfo.put("extraInfo", "myExtraInfo");
   
               JSONObject otherConnectionInfo = new JSONObject();
               otherConnectionInfo.put("type", "myType");
               otherConnectionInfo.put("extraInfo", "myExtraInfo");
   
               prependToNetworkOutputState(this.tvNetworkStateOutputKeepsListening, "equals JSONObjects " + connectionInfo.equals(otherConnectionInfo)); // THIS EQUALS RETURNS FALSE
           } catch (JSONException e) {
   
           }
   ```
   I found something like this on StackOverflow:  _the Android's built-in JSONObject does not define hashCode() and equals() in any sensible way._  
   Check also the Android Docs: [Android Docs](https://developer.android.com/reference/org/json/JSONObject.html)
   
   **Can anyone confirm this?**
   If yes, then we should just correct the equality check.
   
   There is also another path we have to check for state, but that's for later.
   
   Kind regards,
   Pieter


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org