Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to call through super class onCreate and onDestroy methods within an IntentService?

I've derived a class from IntentService and I'm wondering if it is necessary to call through the super class onCreate and onDestroy methods when overriding these methods in my implementation as it happens when you override such methods in an Activity.. If it is necessary, do these invocation need to be the first thing we do in the overriding method? In the Activity documentation they are very clear about that, while in the Service or IntentService docs I can't find anything specific.

like image 970
Gianni Costanzi Avatar asked Dec 27 '22 18:12

Gianni Costanzi


1 Answers

I'm wondering if it is necessary to call through the super class onCreate and onDestroy methods when overriding these methods in my implementation as it happens when you override such methods in an Activity.

Absolutely. Those methods are implemented on IntentService; if you fail to call through to them, your service simply will not work.

If it is necessary, do these invocation need to be the first thing we do in the overriding method?

I would recommend calling super.onCreate() as the first thing that you do in your implementation of onCreate(), and calling super.onDestroy() as the last thing that you do in your implementation of onDestroy().

like image 155
CommonsWare Avatar answered Jan 21 '23 09:01

CommonsWare