BoundSelfStoppingService

Submitted by code_admin on Fri, 07/20/2018 - 13:18

Backgroud

A common problem with android applications I write is that there is no reliable way to close application level resources. The activity life cycle has onPause and onResume but this isn’t useful for resources that need to be maintained from one activity to another.
The best solution that I have found is to create a service that counts whenever an activity binds to it. When the count reaches 0 it waits a certain amount of time then times out running the close code. Then each activity can bind to this service.

Tags