Android service stop working after I run another app/game -
do have idea can bee root cause of android app service stop working when run random app/game?
i not have code available, need causes.
thank you.
service runs in app process. if app garbage collected, service stop until:
- you start service in new process via manifest file declaration
- you make service sticky (recommended).
go ahead , research above 2 , let me know if more explanation or code
update
if see official documentation of service, google explains why , when service destroyed. useful in scenario:
a started service can use startforeground(int, notification) api put service in foreground state, system considers user actively aware of , not candidate killing when low on memory. (it still theoretically possible service killed under extreme memory pressure current foreground application, in practice should not concern.)
using startforeground ensure service keeps running in same process. pointers:
- a service attached client not destroyed on low memory scenarios
- a service killed in low memory scenarios, regardless of process. running in different process better not guarantee won't destroyed system.
- don't use system.exit(0) end app. call finish() on activity.
- starting sticky service ensures service restarted when memory freed.
hope helps!
Comments
Post a Comment