Why is it that you need to call the super class in the android lifecycle? For example, in onCreate you need to call super.onCreate, or onDestroy super.onDestroy.
Asked
Active
Viewed 1,010 times
1 Answers
3
It makes sure that any relevant lifecycle management code across the full class hierarchy gets invoked.
If you have MyBaseActivity
that extends Activity
, and MySpecificActivity
that extends MyBaseActivity
, calling through to the lifecycle methods in the superclass at each level means MyBaseActivity
will still be able to respond to lifecycle events.

adamp
- 28,862
- 9
- 81
- 69
-
Thanks. What do you mean by "still be able to respond to lifecycle events"? – locoboy Mar 22 '11 at 18:45
-
1If superclass A has a method `foo()`, and subclass B of A overrides `foo()`, the code contained in `A#foo()` will not be run when `foo()` is invoked on an instance of class B unless `B#foo()` calls `super.foo();`. – adamp Mar 22 '11 at 18:57
-
1`A.foo()` has code (like tidying resource code) that `B.foo()` won't do unless `B.foo()` calls `super.foo();` – eternalmatt Mar 22 '11 at 21:28