Android kills foreground service when screen sleeps -
in app have timer service. use inside fragment , after calls startservice()
, bindservice()
move foreground.
everything works fine on emulator, on tablet when turn screen off , device sleeps time, service gets killed. there 2 scenarious.
- if device sleeps 3 minutes , wakes able see notification doesn't updates.
- if device sleeps 10 or 15 minutes or more not able see notification when turn screen on.
i heard it's because of battery consumption policy , on devices same service can live more time or doesn't killed depending on such settings, whether device charging , battery status.
i thought start , shut down service when screen wakes , goes sleep respectively. thought broadcast receiver
s can me action_screen_on
, action_screen_off
. unfortunately these actions protected, can registered explicitly (programmatically via calls registerreceiver()
method). can't use them outside of app.
also heard of powermanager
, it's not idea use long time because eat battery quickly.
and yeah use start_sticky
in onstatrcommand()
, can stop , recreate service many times.
so have ideas or hints how make service alive when screen on? in advance.
Comments
Post a Comment