Issue
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 classare definedprotected - But why are they defined as
protected
Solution
- They are
protectedfor 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.
Answered By - Sam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.