https://kotlinlang.org logo
#android
Title
# android
a

Allan Wang

09/27/2018, 1:50 PM
For an activity I have, I want to clean up some files upon on destroy. Would it be better to keep that in a service, or would using coroutines be good enough? The task should be independent of the activity lifecycle, and does not depend on context.
s

Sam

09/27/2018, 2:01 PM
coroutines or threads don't mean anything for Android. Using them without any foreground component like activity just makes your app eligible to be killed before cleanup. Not to mention the fact that starting Android Pie's bucket system, CPU could be relinquished in certain cases
Have some foreground service during cleanup and launch coroutines from that service.
FYI, camera app launches a foreground service for HDR processing of captured photo, food for thought 🙂
a

Allan Wang

09/27/2018, 2:07 PM
Ah okay that was what I was wondering. I usually never use thread pools for this reason.
s

Sam

09/27/2018, 2:08 PM
Yup, few apps just launch threads and burn CPU cycles like crazy. Glad android is going to restrict CPU use https://developer.android.com/about/versions/pie/power#buckets
2 Views