We already have a Lifecycle in our Activity/Fragment then why will we use Lifecycle aware component & kindly guide me the main purpose of it. And if we use lifecycle aware then why we use lifecycle that we knew already
-
Can you please provide more information on your sources? What do you mean with "we already have a Lifecycle"? – bracco23 May 29 '19 at 15:03
-
I meant to say Simple Lifecycle of Activity that we use in our MainActivity OR Fragments.https://developer.android.com/guide/components/activities/activity-lifecycle – Awais Chorahi May 29 '19 at 15:11
-
1Did you read https://developer.android.com/topic/libraries/architecture/lifecycle.html ? – EpicPandaForce May 29 '19 at 15:16
-
EpicPandaForce thank you – Awais Chorahi May 29 '19 at 17:17
2 Answers
Yes the Android Activity has a so called lifecycle
But that has nothing to do with a Lifecycle aware component
Lifecycle-aware components perform actions in response to a change in the lifecycle status of another component, such as activities and fragments. These components help you produce better-organized, and often lighter-weight code, that is easier to maintain.
A common pattern is to implement the actions of the dependent components in the lifecycle methods of activities and fragments. However, this pattern leads to a poor organization of the code and to the proliferation of errors. By using lifecycle-aware components, you can move the code of dependent components out of the lifecycle methods and into the components themselves.
Here´s a tutorial hands-on to make it more easy to understand
So why did Google Android devs come up with this technique and others in the Android jetpack? Yes Lifecycle aware component discussed here comes from Android jetpack from 2018. . They did it to make it easier for us to make robust Android apps. They are doing it to get us closer to the SOLID principles. Before that, developers were coming up with their own styles using homemade MVC,MVVC or MVP. Big discussions on Singletons technique for years and of course how we best do the separation of concern and Single responsibility principle
Now all of that is solved for us with Android jetpack
In object-oriented computer programming, SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable

- 3
- 2

- 5,039
- 10
- 63
- 119
Lifecycle Observer helps you to listen app background and foreground events.
Please find below link for implementation details :

- 1,806
- 22
- 21