In my Android app, the first activity performs various initialization tasks, calculating data that is subsequently used by other activities. There are corresponding termination tasks that free the data. At first glance, it would seem natural to perform the initialization tasks in onCreate and the termination tasks in onDestroy - both in the first activity.
However, since the first activity may be killed by Android while another activity is active, freeing the data in onDestroy would pose a problem for the activity that is still active and wants to access the data.
How does one solve this? It seems I need a way to identify which activity is the last one to be destroyed, so I can perform the termination tasks there.