Application.registerActivityLifecycleCallbacks
is indeed the correct api that you want to use. Unfortunately it is indeed API14+, so you have the following option:
use this library to implement the activitylifecycle callback. You will have to extend your activities in the application you are working on, but something must be done to then no matter what as you need less than API14 support.
With this library implemented, you can create an int
count in the callback. This count can be incremented and decremented every onStart()
and onStop()
callback for each activity.
The count will go from 0 -> 1 on app open, and 1 -> 0 on app close/background. When these conditions are met you can do calls to your library.
Remember that when you background your app the OS can kill it off any time. If you have any amount of networking or anything long, start a service to handle it all as quickly as possible.