Android Question WebView and Websockets

juventino883

Member
Licensed User
Longtime User
Hi! Currently I'm trying to load on a webview a webapp deveolped with B4j and everything is working fine, but when you have the page opened for a while (being innactive) the page stop working like if the websocket gets disconnected, for testing the session timeout is set really hight so I don't think is for that reason, I'm also using automatic reconnecting websocket and everything works great when I'm using chrome browser from my phone and PC but when I'm using webview it seems that the page stop responding after 1minute of innactivity, I'm thinking:

1.- maybe Android is killing the connection?, if thats the case how can be avoided?
2.- webview works with automatic reconnecting websocket?

if someone can help me getting the right direction I will be very gratefull.
 

teddybear

Well-Known Member
Licensed User
From your questions the app should be deveolped with B4a, No codes I don't know what it happens, but I guess you should do something in activity_resume or b4xpages_appear event.
 
Upvote 0

juventino883

Member
Licensed User
Longtime User
hi @teddybear thank you for your answer, reading again my question I see that I forgot to mention that I'm loading one of the pages of my webapp (made in B4j) in a WebView in my B4A app, I was doing more testing and I have changed the webview for ultimateWebview, but now (after some inactivity a couple of minutes) I get a message of "server is not available", this error is new and I'm thinking is related with automatic reconnecting websockets.

I know that automatic reconnecting websockets is intended for web browsers, but I'm not sure if it work with webview?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
hi @teddybear thank you for your answer, reading again my question I see that I forgot to mention that I'm loading one of the pages of my webapp (made in B4j) in a WebView in my B4A app, I was doing more testing and I have changed the webview for ultimateWebview, but now (after some inactivity a couple of minutes) I get a message of "server is not available", this error is new and I'm thinking is related with automatic reconnecting websockets.

I know that automatic reconnecting websockets is intended for web browsers, but I'm not sure if it work with webview?
Ihave tested websockets with webview in my phone for half an hour, everything is ok. perhaps the problem is JavaScript?
 
Upvote 0

juventino883

Member
Licensed User
Longtime User
Hi @teddybear, I have also tested the loading of my webapp and doing some debugging and yes apparently websockets work with webview, and when the connection is killed either by android or because of bad signal, the webscoket is automatically reconnected, but the variables and maps are lost, so what I'm trying is to save those variables into the session and recover them on reconnecting
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hi @teddybear, I have also tested the loading of my webapp and doing some debugging and yes apparently websockets work with webview, and when the connection is killed either by android or because of bad signal, the webscoket is automatically reconnected, but the variables and maps are lost, so what I'm trying is to save those variables into the session and recover them on reconnecting
You may reference to https://www.b4x.com/android/forum/threads/b4x-kvs-keyvaluestore-library.120234/
 
Upvote 0
Top