Using a WebView on Android for WebSocket communication needs to have the WebView attached. But Android does not allow me to add an invisible (size 0,0) WebView for the whole application lifecycle (in iOS this was easy to solve). Unattached WebView will not allow me WebSocket communication.
(a) I tried this with a modeless Dialog which even can span more Activities and it was able to successfully communicate with the server, but i failed handling void onBackPressed() {...} (no access to handle the backstack for myself) and Android sends this to the modeless Dialog instead of the Activity behind it.
(b) So i created a Service like in: Android: Using WebView outside an Activity context. It can load the html/js and can report from js back to java. But i fail to have WebSocket communication although attached.
My question now: either (a) or (b) ... did anyone solve this? I would really prefer (b) if any possibility.