I have a Service, which is foreground. It is locally bound to one (or more) activity, so the activity and the service runs in the same process. There might be some time during which the activity is not displayed (typical music player use case).
If service and activity are in the same process, the memory for the activity can’t be repossessed by operating system, unless the service too is terminated? The answer seems yes to me, according to this article
If the last is true, should I create two separate process:
- To be nice to the system/other apps?
- to be more confident my service will not be killed?
Or, it is not a big deal to have the activity sticking around together with the service?
A “typical music player use case” would not use
bindService()IMHO. A foreground service would not usebindService()IMHO. At minimum, in addition tobindService()for activity->service communication, you would needstartService(), so that after youunbindService()(e.g., user presses BACK), the service can stay running.The memory for the activity is never “repossessed by the operating system”, except by terminating your entire process. Unfortunately, this is not entirely clear from the documentation.
If the user pressed BACK to exit the activity, or you otherwise call
finish()on the activity, the activity should be garbage-collected, assuming nothing is causing it to hang around (e.g., referred to by a static data member).Absolutely not.