Android Question Service in Android

nicieri

Active Member
Licensed User
Longtime User
Hi,

I have a service that start with my phone (at boot), now is working good.. is a service that make a TCP ping every minute, sending a nothing package.. SendData("").. for test the connection.

Every works good, the problem is that after "some minutes.. (disconnected from B4a USB debbuger) release".. the service stopped..

When I connect again the USB cable for see the Log,.. (looking for some error).. the service start again magically and i see all the log..
 

DonManfred

Expert
Licensed User
Longtime User
If you want to care about your battery: Don´t use long running services!

If you need to do even if it drain the batery then you need to aquire a partial lock and use a foregroundservice.
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
also I have my service like Sticky

#StartCommandReturnValue: android.app.Service.START_STICKY
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
also I have my service like Sticky
You are mixing things: Sticky means that the service is recreated when the system does kill it not that the service won't go to sleep.

Use StartForeGround as suggested
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Ok, is just the problem... with newer devices.

Thanks Erel.. so.. the only solution is ForeGround..
 
Upvote 0
Top