gaurav avatar image
gaurav Suspended asked chanel Deactivated edited

TCP Socket in BG service is terminated when device enters sleep mode.

Hi All

I have created a background service in which I am using the tcp socket connection. When the app is live either in background/foreground, the connection is working as expected. But when the clover device goes to sleep, the service is stopped terminating the socket. I have used the WakeLock with PowerManager.PARTIAL_WAKE_LOCK and WifiLock to keep the CPU alive, but this also does not keep the cpu alive. It kills my service again.

Then I used the PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE flags so that my clover device be in DIM state and it works. This is not a correct approach to fix this as this always keep the clover screen ON.

Please let us know the suggested solution for that.
Clover Android SDKClover MiniClover Station
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bryanne Vega avatar image Bryanne Vega commented ·

Any specific reason why your app should retain the TCP connection open?
0 Likes 0 ·

1 Answer

Raymond Lee avatar image
Raymond Lee Deactivated answered
Hi @Gaurav,

Just an FYI, This sounds like an Android question that is non Clover specific, you might get more responses from posting on a different forum.

That being said, it sounds like you are trying to create an never ending background service. The only way to do this is by creating a new service every time your old service is destroyed. Your service will have to re-establish the TCP socket connection when it is started again.

This blog post goes into detail on creating the never ending background service:

Hope that helps,
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community