Android Question Service in Sleep Mode

Pooya1

Active Member
Licensed User
Hi
I connected to server with MQTT protocol in starter service
There are no problem unitl device go to sleep and after 3 minute,mqtt be disconnect
I try use ScreenOn event for reconnect to server again
It is OK
But i need user can receive message when device is sleep after 3 minute
I think Starter is sleep :(
Please guide me
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Hi
I connected to server with MQTT protocol in starter service
There are no problem unitl device go to sleep and after 3 minute,mqtt be disconnect
I try use ScreenOn event for reconnect to server again
It is OK
But i need user can receive message when device is sleep after 3 minute
I think Starter is sleep :(
Please guide me
You need to assert a wake lock to prevent the cpu from going to sleep using PhoneWakeState.

Regards,
Walter
 
Upvote 0

Pooya1

Active Member
Licensed User
A foreground service will prevent the OS from killing your app.
A wake lock will (try to) prevent the device from going to sleep.
I tried use StartServiceAt each 5 minute and if app lost connection,so try to connecting
Thanks
 
Upvote 0

udg

Expert
Licensed User
Longtime User
A foreground service will prevent the OS from killing your app.
A wake lock will (try to) prevent the device from going to sleep.
@Erel : IMHO, a collection of a few statements like those will be able to reduce forum's recurring questions. I mean, a short list of "updated best practices" were only short sentences like "do it this way" will find place. That will suffice to a great part of developers. Then each sentence could refer to a more thorough explanation.
ps: I know that often it doesn't exist a single optimal way to solve a problem but here I am referring to sentences like "prefer maps to lists, never use ExitApplication etc", anything useful to avoid errors or problems to inexperienced new users (and experts alike..eheeh).
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
... and now I'm going to look for what IMHO means :D
upload_2018-8-21_10-19-31.png
 
Upvote 0
Top