For an activity I have, I want to clean up some fi...
# android
a
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
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
Ah okay that was what I was wondering. I usually never use thread pools for this reason.
s
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