Void onDestroy

By implementing these methods, you can monitor two nested loops of the service's lifecycle:

• The entire lifetime of a service happens between the time onCreate() is called and the time onDestroy() returns. Like an activity, a service does its initial setup in onCreate() , and releases all remaining resources in onDestroy() . For example, a music playback service could create the thread where the music will be played in onCreate( ) , and then stop the thread in onDestroy() .

• The active lifetime of a service begins with a call to onStart() . This method is handed the Intent object that was passed to startService() . The music service would open the Intent to discover which music to play, and begin the playback.

There's no equivalent callback for when the service stops — no onStop() method.

The onCreate() and onDestroy() methods are called for all services, whether they're started by

0 0

Post a comment