Friday, January 13, 2012

Is it safe to rely on onDestroy() method of a Service

When running a service (either Service or IntentService doesn't matter), sometimes we need to wrap up things to degrade safely. For this, one can tempt to use onDestroy() method of the Service. However, keep in mind that this method is called by the System and it doesn't guarantee of calling in time: depends on several factors including the memory constraints. Therefore, one should not rely on this method to do critical wrap up operations, such as releasing a wake lock. Same argument is also valid for the Activity. More information can be found on the following links:

http://developer.android.com/guide/topics/fundamentals/services.html
http://developer.android.com/guide/topics/fundamentals.html

No comments:

Post a Comment