Android O, Background Service is running for more than 30 minutes. Why?

微笑、不失礼 提交于 2020-01-01 11:37:12

问题


I am using FusedLocationProvider API to register some Geofences with PendingIntent, when my app gets started (app was manually killed to trigger this behavior) via Geofence event, I start a background service to do some work.

In this Service I create a separate background thread to do some long running tasks and I acquire a wake-lock so that I am sure my tasks are completed. The Service keeps running for longer period of times (30 - 50 minutes) even though It shouldn't be. It shouldn't be white-listed and keep itself running for longer period of times according to my understanding of recent changes in Android O.

Is it desired behavior or some kind of bug with PendingIntents waking up the app and then it's treated like white-listed even though those Intents are not for Notifications (i.e anything which user can see).

Or these intents falls into category of "Receiving a broadcast, such as an SMS/MMS message." as mentioned here in documentation


回答1:


It my be some bug in preview.

But, are you sure your service is running after 1 minute? Your app process and background thread you made will/could run even after service is destroyed.

So your service does pass onDestroy callback, but you don't stop your thread in there and continue doing work in background. It only stops when whole app's process is killed because Android decided it's not important any more.



来源:https://stackoverflow.com/questions/43889604/android-o-background-service-is-running-for-more-than-30-minutes-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!