Links

Sunday, March 10, 2013

Introducing LocalService

Activities has a very short-term lifecycle. Even when you rotate your device, the activity is destroyed and newly created. Therefore, a service is needed for a longer term behavior that should persist when the current application is not in foreground. Service is designed to be a pretty powerful tool, that is intended to support inter-process communication. However, I (and probably you) just use a service as an in-process singleton object for most of the time. Just accessing an object in the same VM need not be complex at all. However, the Android Developer Guide misguides developers to write such a horrible length of code: