What is the reason behind having lifecycle methods of Activity as protected while life cycle methods of fragments are public. I read on link lifecycle methods but couldn't got clear idea. Please explain.
Asked
Active
Viewed 595 times
1
-
*but couldn't got clear idea.* ... seriously, what is wrong with you? *that's because your activity (internally not by you) calls the functions like onCreateView() or in a more abstract and reasoning explanation, because an activity can contain fragments and for fragment-activity communication.* - is pretty clear ... – Selvin Feb 03 '16 at 11:04
1 Answers
1
A Fragment
is meant to be hosted by an Activity
. This means that the host (activity) is responsible of updating the state of it's hosted items (fragments). This will include calling the corresponding lifecycle methods of the fragment instances in accordance with the changes in the activity lifecycle. In order for those methods to be called by classes, external to the whole Fragment
class hierarchy, they have to be public
.

Danail Alexiev
- 7,624
- 3
- 20
- 28