title: Websocket connection wasn't closed after the app killed
body: <p>My Websocket client (OkHttp) doesn't close the connection after the app closed. It opens a new connection every time I open the app which makes the app suffering from multiple messages received on the old and the new Websocket connections from the broadcasting server.</p>
  
  <p>Is that a normal behavior for the android client, as for what I have experienced with web-client, the session was closed properly after the tab killed?</p>
  
  <p>I have been looking up the problem across the internet but no luck so far. I want to make sure whether it happened because of my bad code logic or just the buggy Websocket's implementation from the library?</p>
  
  <p>Here is how I start a new websocket session in the main Activity</p>
  
  <pre><code>var request: Request = Request.Builder()
              .url("ws://$serverIP:8080/example/sim/speed")
              .build()
          var webSocketListener: WebSocketListener = object : WebSocketListener() {
  
              override fun callback(msg: Message) {
                  updateSpeed(msg.content)
              }
  
              override fun onClosing(webSocket: WebSocket?, code: Int, reason: String?) {
                  super.onClosing(webSocket, code, reason)
              }
          }
  
          var webSocket = client!!.newWebSocket(request, webSocketListener)
  
  </code></pre>
  
  <p>After that <code>updateSpeed()</code> will update a text view on UIThread</p>
  
  <p>The <code>onClosed</code> event was not triggered when the app closed but only when the <code>close</code> function called manually.</p>
  
  <p>I'm sure that it opened a new socket every time because I can see new sessions created on the server with different ports.</p>
  
  <p>What I want is to have the app closing its connection before it was closed.</p>
  
  <p>Thank you</p>