My application has multiple activities, and the first (primary) activity is only closed when the app should terminate. All the other (secondary) activities are shown above this one.
This primary activity initializes a Singleton class, that should run for the whole lifetime of the app. The secondary activities use make use of this Singleton instance.
When the app should close, the primary activity handles the termination of the Singleton instance (some steps are required) and terminates itself as well.
I was doing this on the onDestroy method of the primary activity, but it has happened for the method not to be called, which can happen, as per an activity life cycle.
My question is then how should one correctly handle the termination of a Singleton that requires some steps to be taken before termination.
Using the onPause would not work because if the app closed when a secondary activity was showing, the onPause of the primary activity would not be called again (as it was already hidden).
Thanks!