0

I have a web app that is now being used in an Android app by launching it in a webview. Most of the Android functionality is native & the webview part is mainly just for communication via socket.io

It all works okay but as soon as the phone goes to sleep it kills the socket connection after a few minutes. This connection is used for incoming messaging so I need the connection to stay alive.

I tried creating a foreground service and using it as a keep-alive but since the socket connection is in the webview, it still gets closed no matter what I do i.e. the service stays alive and I can make a new network connection, but I can't keep the existing app connection alive.

Is there a way to keep a webview socket connection alive when the phone dozes? Am I doing something wrong? Or is my design flawed and I need a different approach?

Spider-Paddy
  • 303
  • 2
  • 14
  • Have you tried [using the Java Socket.IO library](https://github.com/socketio/socket.io-client-java) instead of the `WebView`? – CommonsWare Jul 05 '21 at 15:09
  • @CommonsWare I haven't tried that. We just migrated the project as it was, and as such used a webview. I'll try that out. Thanks. – Spider-Paddy Jul 06 '21 at 09:38

0 Answers0