Noes from the Service chapter in Pro Android 4.
- onCreate() method where you can do initialization
- onDestroy() method where you can do cleanup
- Prior to Android 2.0, a service had an onStart() method and since 2.0 it’s called onStartCommand(). The difference between the two is the addition of a flags parameter, which is used to specify to the service that an intent is being redelievered or that the service should restart.
- Services don’t pause or resume the way activites do so we do use onPause() or onResume() methods. For local service, we won’t be binding to it, but because Service requires an implementation of the onBind() method, we provide one that simply returns null.
- When an intent is sent into our service using startService(), onCreate() is called if necessary, and our onStartCommand() method is called to receive the caller’s intent. We should expect any data to be passed to us via the intent, and this could include URIs for example.
- onDestroy() menthod is where to preform cleanup. Like to get rid of threads created earlier. Otherwise threads could simply hang around and take up memory.