we have an application, which is originally targeting desktops and we ported it to Android 8, changing only the parts really needed, so we can stay with one common code base, using
#ifdefs where needed.
My problem is now, that the application is expected to send regular packets to a server and also actively listen on a TCP connection. This works fine on a desktop. On Android this works also fine as long as the app is in foreground and display is on (or the USB charger connected). Once the app goes into doze no network interaction takes place.
I've read Sending keep-alive Messages on Android even if the device is in sleep/doze mode, where the OP seemed to have realized exactly, what I needed, by creating a foreground service and using that to keep the activity awake. I tried that and managed to create a foreground service, but just the existence of a bound foreground service does not seem to keep the activity awake and the event loop running.
Then I read somewhere that the activity is kept in foreground, if the foreground service runs in the same process, but that didn't seem to help either. (Also I had to derive my service from
android.app.Service directly, because that doesn't work with
QtService and I don't understand the side effects).
I don't know what I missed. All I need is grant execution resources to the activity from my service every few seconds. I know I could move the network connection stuff to the service, but that would mean a huge code change and introduce inconsistencies with other platforms.
Do you have any ideas what I could be missing?