Usually resources such as threads, services, memory allocation... are allocated and defined per Activity. Hence, resources will be allocated on Activity.onCreate() and freed on Activity.pause(). This is very well defined.
But, suppose my resources are allocated per Application (i.e I define a service which is used by several activities, OR, I instantiate a thread in the Native layer using NDK). Allocating these resources is not a problem. It can simply be done when the first Activity starts. The problem is - when should these resources by freed? How do I know when my application ends? According to the documentation: http://developer.android.com/reference/android/app/Application.html#onTerminate() - " Note: never depend on this method being called; in many cases an unneeded application process will simply be killed by the kernel without executing any application code."
Any ideas anyone?
Thanks, Eyal