<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>#Lifecycle Archives - anteelo</title>
	<atom:link href="https://anteelo.com/tag/lifecycle/feed/" rel="self" type="application/rss+xml" />
	<link>https://anteelo.com/tag/lifecycle/</link>
	<description>Leading Digital Solution Firm</description>
	<lastBuildDate>Thu, 17 Jun 2021 11:15:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://anteelo.com/wp-content/uploads/2020/01/cantlogo.png</url>
	<title>#Lifecycle Archives - anteelo</title>
	<link>https://anteelo.com/tag/lifecycle/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Android Architecture Components: Exploring</title>
		<link>https://anteelo.com/android-architecture-components-exploring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-architecture-components-exploring</link>
		
		<dc:creator><![CDATA[Anteelo Master]]></dc:creator>
		<pubDate>Wed, 30 Jan 2019 11:11:06 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[#android]]></category>
		<category><![CDATA[#Architecture]]></category>
		<category><![CDATA[#components]]></category>
		<category><![CDATA[#Lifecycle]]></category>
		<category><![CDATA[#LiveData]]></category>
		<guid isPermaLink="false">https://anteelo.com/?p=3509</guid>

					<description><![CDATA[<p>At Google I/O 2017, Google introduced new architecture components for Android. It is a new library which will help developers to maintain their activities or fragments lifecycle very easily. This new library by Google provides some relief to the Android Developers by providing a complete solution to problems like memory leaks, data persistence during configuration changes [&#8230;]</p>
<p>The post <a href="https://anteelo.com/android-architecture-components-exploring/">Android Architecture Components: Exploring</a> appeared first on <a href="https://anteelo.com">anteelo</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div align="justify">At Google I/O 2017, Google introduced new architecture components for Android. It is a new library which will help <a href="https://www.instagram.com/anteelodesign/">developers</a> to maintain their activities or fragments lifecycle very easily.</div>
<div align="justify">
<p>This new library by Google provides some relief to the <a href="https://anteelo.com/contact">Android Developers</a> by providing a complete solution to problems like memory leaks, data persistence during configuration changes and also helps in reducing some boilerplate code.</p>
<p><img decoding="async" class="aligncenter" src="https://lh3.googleusercontent.com/proxy/bXBhasq0HVANd47ePauAvHtbY59F-EGrURHmoabIP9QeF5iEctm5R108iy-jLCj-BbjkQNxWbmb5dSKrZ5R_S3lIQKg9ZotZNXwxsdB5IKssnXM6t60v6I2rWaGSK_IBGWB-OgFAyNemO6pE-yBn4Z6Q-rGllMJniL068g" alt="Exploring the new Android Architecture Components (Part 1) | Humble Bits" /></p>
<p>There are 4 Android Architecture Components :</p>
<ol>
<li>Lifecycle</li>
<li>LiveData</li>
<li>ViewModel</li>
<li>Room</li>
</ol>
<p><img fetchpriority="high" decoding="async" class="aligncenter" src="https://miro.medium.com/max/468/1*M60CvQO3ClCt_oPZ5U-Jmw.png" alt="LiveData Clean Code using MVVM and Android Architecture Components | by Rohit Singh | AndroidPub | Medium" width="338" height="432" /></p>
<h3>Lifecycle</h3>
<p>Lifecycle class helps us in building lifecycle aware components. It is a class which holds all the information about the states of an activity or a fragment. It allows other objects to observe lifecycle states like a resume, pause etc.</p>
<p>There are 2 main methods in the Lifecycle class:</p>
<ol>
<li><strong>addObserver()</strong> – Using this method, we can add a new instance of a “<strong>LifecyleObserver</strong>” class which will be notified whenever our “<strong>LifecycleOwner</strong>” changes state. <em>For example</em>: if an activity or a fragment is in RESUMED state then our “<strong>LifecycleObserver</strong>” will receive the ON_RESUME event.</li>
<li><strong>removeObserver()</strong> – This method is used for removing active “<strong>LifecycleObserver</strong>” from the observer’s list.</li>
</ol>
<h4>LifecycleObserver</h4>
<p>With the help of this interface, we can create our Observer class which will observe the states of an activity or a fragment. We need to simply implement this “LifecycleObserver” interface.</p>
<h4>LifecycleOwner</h4>
<p>It is an interface with a single method called <strong>“getLifecycle()”. </strong>This method must be implemented by all the classes which are implementing this interface. This interface denotes that this component (an activity or a fragment) has a lifecycle.</p>
<p>Any class <b>whose</b> states we want to listen must implement the <b>“LifecycleRegistryOwner” </b>interface. And any class <b>who </b>wants to listen must implement the “<b>LifecycleObserver” </b>interface.</p>
<p>There are several events which we can listen with the help of the “LifecycleObserver” interface:</p>
<ul>
<li>ON_CREATE – Will be called <strong>after onCreate() method</strong> of the “<strong>LifecycleOwner</strong>”.</li>
<li>ON_START – Will be called <strong>after onStart() method </strong>of the “<strong>LifecycleOwner</strong>”.</li>
<li>ON_RESUME -Will be called <strong>after onResume() method </strong>of the “<strong>LifecycleOwner</strong>”.</li>
<li>ON_PAUSE – Will be triggered upon the “<strong>LifecycleOwner</strong>” being paused (<strong>before</strong> <strong>onPause()</strong> method).</li>
<li>ON_STOP – Will be triggered upon the “<strong>LifecycleOwner</strong>” being stopped (<strong>before</strong> <strong>onStop()</strong> method).</li>
<li>ON_DESTROY – Will be triggered by the “<strong>LifecycleOwner</strong>” being destroyed (<strong>before</strong> <strong>onDestroy()</strong> method).</li>
</ul>
<p>All these events are enough for managing the lifecycle of our views. With the help of these  <strong>“LifecycleObserver”</strong> and <strong>“LifecycleOwner”</strong> classes, there is no need to write methods like onResume(), onPause() etc in our activities or fragments. We can handle these methods in our observer class.</p>
<p>We can also get the current state of the <strong>“Lifecycle Owner” </strong>with the help of <strong>getCurrentState() </strong>method.</p>
<h3>LiveData</h3>
<p>LiveData is a data holder class. It provides us the ability to hold a value and we can observe this value across lifecycle changes.</p>
<p>Yeah, you heard that right!</p>
<p><strong>LiveData</strong> handles the lifecycle of app components automatically. We only need to observe this <strong>LiveData</strong> class in our components. That’s it and we are done.</p>
<p>There are some important methods of LiveData:-</p>
<ul>
<li>onActive() – Called when there is an active observer. An observer is called active observer when its lifecycle state is <strong>either</strong> <strong>STARTED</strong> <strong>or</strong> <strong>RESUMED </strong>and the number of active observers changes from 0 to 1.</li>
<li>onInactive() – Called when there are no active observers. An observer is called inactive observer when its lifecycle state is<strong> neither STARTED nor RESUMED</strong> (like an activity in the back stack) and the number of active observers changes from 1 to 0.</li>
<li>setValue() – Used to dispatch the results to the active observers. This method must be called from the<strong> main thread</strong>.</li>
</ul>
<p>In above method <strong>observe() </strong>we pass the Lifecycle Owner as an argument, this argument denotes that <strong>LocationHelperLiveData</strong> class should be bound to the <strong>Lifecycle</strong> of the <strong>MyActivity</strong> class. This bounding relationship of helper class with our Activity denotes that:-</p>
<ul>
<li>Even if the value changes, the observer will not be called if the Lifecycle is not in an active state (STARTED or RESUMED).</li>
<li>The observer will be removed automatically if the Lifecycle is destroyed.</li>
</ul>
<p>Whenever <strong>MyActivity</strong> is in<strong> either PAUSE or STOP</strong> state it will not receive location data. It will start receiving Location Data again once <strong>MyActivity </strong>is in <strong>either RESUME or START</strong> state.</p>
<p>There can be multiple Activities or Fragments which can observe <strong>LocationHelper</strong><strong>LiveData </strong>instance and our LiveData class will manage their Lifecycle automatically.</p>
<p>There is no need to remove observer in <strong>onDestroy()</strong> method, it will be removed automatically once <strong>LifecycleOwner</strong> is destroyed.</p>
</div>
<p>The post <a href="https://anteelo.com/android-architecture-components-exploring/">Android Architecture Components: Exploring</a> appeared first on <a href="https://anteelo.com">anteelo</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
