Can I still have a data logging background service in Android 8.0?

前端 未结 1 681
野的像风
野的像风 2020-12-12 03:21

My app relies on logging the battery temperature, as well as several other sensor variables, every second in a background service that can be started from the main activity

相关标签:
1条回答
  • 2020-12-12 03:36

    If your usecase is to keep the app in foreground during this processing then, based on the documentation, there shouldn't be any problem, since the restrictions for background service is applied if your app is not in Foreground or no foreground app is connected to the app

    X minutes (based on my observations its around 1 - 2 minutes) after your app enters in background all the restrictions for background service will kick in and your Service will be stopped as if you have called Service.stopSelf()

    You should avoid doing it continuously, since it will impact battery life of the device, if are intending to do in background. You can perform logging periodically using JobScheduler/AlarmManager.

    If you still want to proceed, you can make the service ForegroudService and perform the operation but if system considers your task as CPU intensive then this approach wont' work either

    0 讨论(0)
提交回复
热议问题