0

The WebView loads a webpage which uses socket.io

WebView myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl(socket_io_page_url);

The session is maintained using cookies. When the android logout action item is activated the cookies must be cleared and a new url is loaded as shown in the following code

WebView myWebView = (WebView)findViewById(R.id.webView);
CookieManager.getInstance().removeAllCookie();
myWebView.loadUrl(new_url);

This works but the connection to the previous url(socket_io_page_url) is not terminated immediately. Since the WebView does not support web sockets, the long-polling is used by the webview and it waits about 20 seconds to disconnect the previous url. The time out can be changed, but it will be a very bandwidth costly operation.

At this point it is not possible to switch to native java coding. So disconnecting the previous connection is very important to the application. I tried

myWebView.destroy()

System.gc()** after new url load,

webSettings.setJavaScriptEnabled(false); and setting back
webSettings.setJavaScriptEnabled(true);

None of them worked. killing the application using cleaner application disconnects the socket immediately. Is there a way to disconnect the previously loaded page.

Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135

0 Answers0