Why are lifecycle methods in activity class defined with protected access specifier

android, android-lifecycle, java

Solution

- They are `protected` for encapsulation within the framework package android.app and subclasses.

- They are to be called by `android.app.ActivityManager` (same package) only. Depending on the method implementation, things could get messed up, if one can call those methods arbitrarily, from anywhere.

So, this is by design and that design helps to avoid certain conceptual errors. If you really must have a `public` method, just implement one and use it from outside and within the corresponding lifecycle method. However, though not recommended in this case, one could override `protected` methods with `public` methods.

Problem

Why are the lifeCycle methods in android have access specifiers as `protected` ? what i understand about Access-specifiers is as below:: - But why should we need to make all the life-cycle methods as protected - I notice this when i override the lifecycle methods - I know over-riding the methods of Activity class as methods in `Activity class` are defined `protected` - But why are they defined as `protected`

Original source

Related problems