<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Châu Anh on Medium]]></title>
        <description><![CDATA[Stories by Châu Anh on Medium]]></description>
        <link>https://medium.com/@chauanh19981998?source=rss-db55cd48c1db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*APOOk98QSiUPqKEapc_V9g.jpeg</url>
            <title>Stories by Châu Anh on Medium</title>
            <link>https://medium.com/@chauanh19981998?source=rss-db55cd48c1db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:33:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chauanh19981998/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Jetpack Compose]]></title>
            <link>https://medium.com/@chauanh19981998/jetpack-compose-67ad2e05dcc?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/67ad2e05dcc</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 07:23:06 GMT</pubDate>
            <atom:updated>2022-06-07T07:23:06.063Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>What’s Jetpack Compose</strong></h4><p>Jetpack compose is a modern Android UI toolkit introduced by Google. It simplifies the app development process and speeds it up. With Jetpack Compose, you can write less code compared to the current view building approach — which also means less potential bugs. There is one more great thing about it — it uses Kotlin. If you have been using React or Flutter, you will probably be familiar with the concept and find many similarities.</p><p>Jetpack Compose aims to simplify and accelerate UI development for Android apps by allowing programmers to define their UIs using a declarative style.</p><p>In the new era, declarative coding is proven much more efficient and productive than imperative coding.</p><p>This method helps user to reduce line of code as well as to improve debugging efficiency. It also improves the runtime performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJCubPgDmJmNT6PKXXqpzw.png" /></figure><h4><strong>The Declarative Approach</strong></h4><p>Jetpack Compose is built upon a different programming paradigm. It uses a declarative paradigm. To put it shortly, it means that you have to change your way of thinking from: <strong>“How to do something” </strong>to <strong>“What goal I want to achieve”</strong>. In a declarative way of programming, you try to describe an expected result instead of describing every step to achieve the goal. In the previous example we simply said “I want to have a column with three texts inside” — and that is all. We don’t need to write any extra code that tells the app how to deal with the items inside the column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghrrl-DfdRpPspXHDHAV7w.png" /></figure><p>In above code base we are defining compose UI elements and the resulting output for this code base will look like below. Here we can mainly use core foundation components such as Row &amp; Column (Similar to Table layout), Surface and Space (to determine spacings) and Text (similar to TextView) and Material components such as Card and SnackBars.</p><p>These components are introduced with certain properties like modifier and style based on the utilities so more attributes can be explored by class definition. And this components are declared same as we create object with arguments in constructor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0fNZABqbBrhe-aIX_nvRNA.png" /></figure><p>We can preview the current UI inside android studio without running the application using @Preview annotation. To perform that we need to call our composable function inside preview method as shown in above code base</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*5ePdTkNIZBm6JWdFHWJR2A.png" /></figure><h4>Summary</h4><p>Jetpack Compose is a promising and powerful modern UI toolkit that you definitely should keep an eye on. If used correctly, it can speed up the development process and reduce the size of the app. Moreover, with Compose you write less code — which, potentially, means fewer bugs. Thank you for reading.</p><h4>For More Information</h4><p><a href="https://developer.android.com/jetpack/compose">https://developer.android.com/jetpack/compose</a></p><p><a href="https://codelabs.developers.google.com/jetpack-compose-adaptability#0">https://codelabs.developers.google.com/jetpack-compose-adaptability#0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67ad2e05dcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ProGuard In Android]]></title>
            <link>https://medium.com/@chauanh19981998/proguard-in-android-85df7fb8ab1f?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/85df7fb8ab1f</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 07:23:04 GMT</pubDate>
            <atom:updated>2022-03-07T07:23:04.285Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s ProGuard?</h4><p>ProGuard is a free java tool in Android, which helps us to do the following</p><ul><li>Shrink the code: Remove unused code in the project.</li><li>Obfuscate the code: Rename the names of class, fields, etc.</li><li>Optimize the code: Do things like inlining the functions.</li></ul><p>In short, ProGuard makes the following impact on our project,</p><ul><li>It reduces the size of the application.</li><li>It removes the unused classes and methods.</li><li>It makes the application difficult to reverse engineer by obfuscating the code.</li></ul><h4>Why ProGuard for Android?</h4><p>Android Applications are quite easy to reverse engineer, so if you want to prevent this from happening, you should use Proguard for its main function Obfuscation, example: Proguard will changes the names to some smaller names like for <strong>UserModel</strong> it might change the name to <strong>A</strong>. The other two important functions of Proguard are Shrinking and Optimization. Shrinking eliminates unused codes and it is highly useful. Optimization operates with java bytecode, though, since Android runs on special bytecode which is converted from java bytecode some optimizations won’t work well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Efb2XrCjgpRcuAlk.png" /><figcaption>Obfuscating the code. (<a href="https://kipalog.kaopiz.com/posts/Doc-di-se-to-chu-de">https://kipalog.kaopiz.com/posts/Doc-di-se-to-chu-de</a>)</figcaption></figure><p>In picture above, this is a way of obfuscating the code, making it unreadable to prevent translation and steal the resource code.</p><h4>How to use it in our project?</h4><p>To enable Proguard in your project, in the app’s build.gradle add,</p><pre>android {<br>    buildTypes {<br>        release {<br>            // Enables code shrinking, obfuscation, and optimization for only<br>            minifyEnabled true<br><br>            // Enables resource shrinking<br>            shrinkResources true<br><br>            // Includes the default ProGuard rules files that are packaged<br>            proguardFiles getDefaultProguardFile(<br>                    &#39;proguard-android-optimize.txt&#39;),<br>                    &#39;proguard-rules.pro&#39;<br>        }<br>    }<br>    ...<br>}</pre><h4>Shrink your code</h4><p>Code shrinking is enabled by default when you set the minifyEnabled property to true.</p><p>Code shrinking is the process of removing code that determines is not required at runtime. This process can greatly reduce your app’s size if, for example, your app includes many library dependencies but utilizes only a small part of their functionality.</p><h4>Shrink your resources</h4><p>Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. You must remove unused library code so the library resources become unreferenced and removable by the resource shrinker.</p><p>To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking).</p><p>But it can be too much sometimes when the proguard removes too much code and it might break your code for the flow.</p><p>So, configuring the code we have to add some custom rules to make sure we remove the set of code from obfuscating. We can fix this by writing out custom rules in our proguard and it will respect while generating the build.</p><p>Now, let us see how we can write custom rules in proguard.</p><h4>Keeping class files</h4><p>Let say we have a data class, which is needed by some API to perform but which generating a build we obfuscate the class. For example, we have a User class</p><pre>class <strong>User </strong>{val id: String = &quot;&quot;}</pre><p>and we want not to obfuscate the class which generating build then to ignore it from obfuscating we use <strong>@Keep</strong> annotation and update the code like,</p><pre><strong>@Keep</strong><br>class <strong>User </strong>{val id: String = &quot;&quot;}</pre><p>This annotation helps the class to be ignored by using proguard while minified. This will preserve the class and its member functions even when they are not in use.</p><h4>Keeping the members for a class</h4><p>Let’s say we want to preserve only the class members and not the class while shrinking, then we use -keepclassmember in the proguard rule file. This will help us to ignore members of a specific class.</p><p>Consider the above User class, and we want to preserve all the public methods inside it. We write the rule like,</p><pre>-keepclassmembers <strong>class</strong> <strong>User </strong>{<br>    public ...;<br>}</pre><p>Here, the class User keeps all the members all which have public modifiers.</p><h4>Keeping names of the class and members</h4><p>Let’s say we want to keep all the same names of the class and members of a class if it’s being used in the code. If the class is not used it would be shrunk by proguard but not obfuscated because it has already been shrunk there is no need of obfuscation. To do the above task we use -keepnames</p><pre>-keepnames <strong>class</strong> <strong>User </strong>{<br>    private ...;<br>}</pre><p>Here, if the GlideModule would keep all of its names of the class and the member function.</p><h4>Only Obfuscate your project</h4><p>Consider a very rare use case, where you just want to obfuscate the code and not shrink any resource. This is a very rare use case but might be useful for some small libraries, then we write the flags like,</p><pre>-dontshrink<br>-dontoptimize</pre><p>This will help us to not shrink and optimize the code and just obfuscate.</p><p>This’s the end of ProGuard Android, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://developer.android.com/studio/build/shrink-code">https://developer.android.com/studio/build/shrink-code</a></p><p><a href="https://kipalog.kaopiz.com/posts/Doc-di-se-to-chu-de">Đọc đi sẽ tỏ chủ đề!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85df7fb8ab1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intent Android]]></title>
            <link>https://medium.com/@chauanh19981998/intent-android-466dc8b1fb6a?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/466dc8b1fb6a</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 10:34:02 GMT</pubDate>
            <atom:updated>2022-03-04T10:34:02.983Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s Intent ?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yd1E59p-wPXEgTOnYsyE-A.png" /><figcaption><strong>Intent example</strong></figcaption></figure><p><strong>Intent</strong> is the message that is passed between components such as activities, content providers, broadcast receivers, services etc.</p><p>It is generally used with startActivity() method to invoke activity, broadcast receivers etc.</p><p>The <strong>dictionary meaning</strong> of intent is intention or purpose. So, it can be described as the intention to do action.</p><p>The LabeledIntent is the subclass of android.content.Intent class.</p><p>Android intents are mainly used to:</p><ul><li>Start the service</li><li>Launch an activity</li><li>Display a web page</li><li>Display a list of contacts</li><li>Broadcast a message</li><li>Dial a phone call etc.</li></ul><h4>Types of Android Intents</h4><p>There are two types of intents in android: implicit and explicit.</p><h4>Implicit Intent</h4><p><strong>Implicit Intent</strong> doesn’t specify the component. In such case, intent provides information of available components provided by the system that is to be invoked.</p><p>For example, you may write the following code to view the webpage.</p><pre>Intent intent=<strong>new</strong> Intent(Intent.ACTION_VIEW);</pre><pre>intent.setData(Uri.parse(“http://www.medium.com&quot;));</pre><pre>startActivity(intent);</pre><h4>Explicit Intent</h4><p><strong>Explicit Intent</strong> specifies the component. In such case, intent provides the external class to be invoked.</p><pre>Intent i = <strong>new</strong> Intent(getApplicationContext(), ActivityTwo.<strong>class</strong>);</pre><pre>startActivity(i);</pre><p>Now, we will create code example using <strong>Intent</strong> to start new activity with old activity.</p><p><strong>File: activity_main.xml. (First Activity layout)</strong></p><pre>&lt;?xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot;?&gt;<br>&lt;android.support.constraint.ConstraintLayout<br>xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; xmlns:tools = &quot;http://schemas.android.com/tools&quot; android:layout_width = &quot;match_parent&quot;<br>   android:layout_height = &quot;match_parent&quot;&gt;<br>&lt;LinearLayout<br>   android:layout_width = &quot;match_parent&quot;<br>   android:layout_height = &quot;match_parent&quot;<br>   android:gravity = &quot;center&quot;<br>   android:orientation = &quot;vertical&quot;&gt;<br>   &lt;Button<br>      android:layout_width = &quot;wrap_content&quot;<br>      android:layout_height = &quot;wrap_content&quot;<br>      android:text = &quot;Send to another activitys&quot;<br>      android:id = &quot;@+id/send&quot;/&gt;<br>&lt;/LinearLayout&gt;<br>&lt;/android.support.constraint.ConstraintLayout&gt;</pre><p>Create a new layout <strong>activity_second.xml. (Second Activity layout )</strong> in res/layout/ folder and add the following code</p><pre>&lt;?xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot;?&gt;<br>&lt;android.support.constraint.ConstraintLayout xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot;<br>   xmlns:app = &quot;http://schemas.android.com/apk/res-auto&quot;<br>   xmlns:tools = &quot;http://schemas.android.com/tools&quot;<br>   android:layout_width = &quot;match_parent&quot;<br>   android:layout_height = &quot;match_parent&quot;<br>   android:layout_centerInParent = &quot;true&quot;<br>   android:layout_centerHorizontal = &quot;true&quot;<br>   tools:context = &quot;.SecondActivity&quot;&gt;<br>   &lt;TextView<br>      android:id = &quot;@+id/data&quot;<br>      android:textSize = &quot;20sp&quot;<br>      android:layout_width = &quot;wrap_content&quot;<br>      android:layout_height = &quot;wrap_content&quot; /&gt;<br>&lt;/android.support.constraint.ConstraintLayout&gt;</pre><p>Add the following code to <strong>MainActivity.java (First activity)</strong></p><pre>import android.content.Intent;<br>import android.os.Bundle;<br>import android.support.v7.app.AppCompatActivity;<br>import android.view.View;<br>import android.widget.Button;<br>public class MainActivity extends AppCompatActivity {<br>   @Override<br>   protected void onCreate(Bundle savedInstanceState) {<br>      super.onCreate(savedInstanceState);<br>      setContentView(R.layout.activity_main);<br>      Button send = findViewById(R.id.send);<br>      send.setOnClickListener(new View.OnClickListener() {<br>         @Override<br>         public void onClick(View v) {<br>            Intent send = new Intent(MainActivity.this,     SecondActivity.class);<br>            startActivity(send);<br>         }<br>      });<br>   }<br>}</pre><p>In the above activity we are starting new activity using startActivity(). To start activity, we need to create new intent and we have to pass current activity and new activity as shown below.</p><pre>Intent send = new Intent(MainActivity.this, SecondActivity.class);<br>startActivity(send);</pre><p>Create a new activity and add the following code to <strong>SecondActivity.java (Second Activity)</strong></p><pre>package com.example.java.myapplication;<br>import android.support.v7.app.AppCompatActivity;<br>import android.os.Bundle;<br>import android.widget.TextView;<br>public class SecondActivity extends AppCompatActivity {<br>   @Override<br>   protected void onCreate(Bundle savedInstanceState) {<br>      super.onCreate(savedInstanceState);<br>      setContentView(R.layout.activity_second);<br>      TextView data=findViewById(R.id.data);<br>      data.setText(&quot;This is second activity&quot;);<br>   }<br>}</pre><p>Let’s try to run application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*lTDAV7V5lksjeX2PCjFYRA.jpeg" /><figcaption><strong>Main Screen</strong></figcaption></figure><p>Now click on Button to start new activity as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*KP0-M5icTNAyj3v733dfmg.jpeg" /><figcaption><strong>Second Screen</strong></figcaption></figure><p>This’s the end of Android Intent, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://developer.android.com/reference/android/content/Intent">https://developer.android.com/reference/android/content/Intent</a></p><p><a href="https://vntalking.com/intent-trong-android-va-cach-su-dung.html">Intent trong Android: Vai trò và cách sử dụng - VNTALKING</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=466dc8b1fb6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Application Components]]></title>
            <link>https://medium.com/@chauanh19981998/android-application-components-5869acaae1ad?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/5869acaae1ad</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 10:21:57 GMT</pubDate>
            <atom:updated>2022-03-04T10:21:57.298Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s Application Component</h4><p>Application components are the essential building blocks of an Android application. These components are loosely coupled by the application manifest file <strong>AndroidManifest.xml</strong> that describes each component of the application and how they interact.</p><p>There are following four main components that can be used within an Android application</p><h4>Activities</h4><p>An activity represents a single screen with a user interface, in-short Activity performs actions on the screen. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched.</p><p>An activity is implemented as a subclass of <strong>AppCompatActivity</strong> class as follows</p><pre>public class MainActivity extends AppCompatActivity {<br>}</pre><h3>Content Providers</h3><p>A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the <strong>ContentResolver </strong>class. The data may be stored in the file system, the database or somewhere else entirely.</p><p>A content provider is implemented as a subclass of <strong>ContentProvider</strong> class and must implement a standard set of APIs that enable other applications to perform transactions.</p><pre>public class MyContentProvider extends  ContentProvider {<br>   public void onCreate(){}<br>}</pre><h4>Services</h4><p>A service is a component that runs in the background to perform long-running operations. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity.</p><p>A service is implemented as a subclass of <strong>Service</strong> class as follows</p><pre>public class MyService extends Service {<br>}</pre><h4>Broadcast Receivers</h4><p>Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action.</p><p>A broadcast receiver is implemented as a subclass of <strong>BroadcastReceiver</strong> class and each message is broadcaster as an <strong>Intent</strong> object.</p><pre>public class MyReceiver  extends  BroadcastReceiver {<br>   public void onReceive(context, intent){}<br>}</pre><h3>Additional Components</h3><h4>Fragments</h4><p>In Android a <strong>fragment</strong> is a fragment of a total user interface. A fragment typically only takes up part of the screen. Fragments are used inside activities. Fragments can be reused within different activities. Fragments typically contains Views and ViewGroups inside them.</p><h4>Layout XML Files</h4><p>Activities, fragments and some ViewGroups can use XML files to define their layout and contents. The layout XML files specify what GUI (Graphical User Interface) components an activity or fragment contains, as well as styling of the GUI components (size, margins, padding etc.).</p><h4>Intents</h4><p>Android <strong>intents</strong> are small objects that an activity can pass to the Android operating system, to tell the operating system that some other action or activity is required. For instance, a photo app may send an intent to the operating system when the user has chosen to share a photo. The intent describes the “sharing action”. Other applications that knows how to perform the “sharing action” can then be opened, and the sharing can be performed via another application.</p><h4>Widgets</h4><p>Widgets are variations of Broadcast Receivers and essential aspects of home screen customization. They display data and allow users to perform actions on them. There are various types of widgets</p><ul><li><strong>Information widget</strong>: These widgets display crucial information and track how the information changes over time. Example - Clock widgets display time information.</li><li><strong>Collection widget</strong>: As the name depicts, collection widgets are a collection of information of the same type. Its use is for browsing information and opening any one of the elements to view details. Example music widgets, as we can skip pause and play music outside the music application.</li><li><strong>Control widget</strong>: These widgets display functionalities and by using them, the user can trigger from home screen without opening the application. Example - pause and play the video outside the application.</li><li><strong>Hybrid widget</strong>: These widgets combine features of all the other three widgets. Example - music player widget is a control widget but it also informs the user about which track is playing currently, which means it is a combination of control and information thus it is termed as hybrid widget.</li></ul><h4>Views and View Groups</h4><p>Android GUI elements fall into three categories: Activities, Views and View Groups. Activities are the screens / windows. Views are the individual GUI elements, like a Text View displaying a text, a Button that users can click on etc. View Groups are containers for Views. A View Group groups a collection of Views together. Views and View Groups can be nested inside an activity or inside a fragment (which is again nested inside an activity).</p><h4>Resources</h4><p>Resources in Android refer to things like images, strings, and other material that your application uses but is not in the form of some programming language source code. UI layouts are another type of resource. You will create these layouts either using a structured tool, such as an IDE’s drag-and-drop GUI builder, or by hand in XML form. You will be able to put resources into resource sets that indicate under what circumstances those resources can be used (e.g., use these for normal-sized screens, but use those for larger screens).</p><p>This’s the end of Android Application Components, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://data-flair.training/blogs/android-application-components/">https://data-flair.training/blogs/android-application-components/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5869acaae1ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Activity Lifecycle]]></title>
            <link>https://medium.com/@chauanh19981998/android-activity-lifecycle-7c43a408959c?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c43a408959c</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 08:24:53 GMT</pubDate>
            <atom:updated>2022-03-04T08:24:53.131Z</atom:updated>
            <content:encoded><![CDATA[<p>Android system initiates its program with in an <strong>Activity</strong> starting with a call on <em>onCreate()</em> callback method. There is a sequence of callback methods that start up an activity and a sequence of callback methods that tear down an activity as shown in the below Activity life cycle diagram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*ZCN982qXPJmgJ8-eZHHH4g.png" /><figcaption><strong>Activity life cycle diagram</strong></figcaption></figure><p>You don’t need to implement all the callbacks methods. However, it’s important that you understand each one and implement those that ensure your app behaves the way users expect.</p><p><strong>onCreate(): </strong>This is the first callback and called when the activity is first created.</p><p><strong>onStart(): </strong>This callback is called when the activity becomes visible to the user.</p><p><strong>onResume(): </strong>This is called when the user starts interacting with the application.</p><p><strong>onPause(): </strong>The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed.</p><p><strong>onStop(): </strong>This callback is called when the activity is no longer visible.</p><p><strong>onDestroy(): </strong>This callback is called before the activity is destroyed by the system.</p><p><strong>onRestart(): </strong>This callback is called when the activity restarts after stopping it.</p><h4><strong>Code Example</strong></h4><pre>package com.example.helloworld;<br><br>import android.os.Bundle;<br>import android.app.Activity;<br>import android.util.Log;<br><br>public class MainActivity extends Activity {<br>   String msg = &quot;Android : &quot;;<br>   <br>   /** Called when the activity is first created. */<br>   @Override<br>   public void <strong>onCreate</strong>(Bundle savedInstanceState) {<br>      super.onCreate(savedInstanceState);<br>      setContentView(R.layout.activity_main);<br>      Log.d(msg, &quot;The onCreate() event&quot;);<br>   }<br><br>   /** Called when the activity is about to become visible. */<br>   @Override<br>   protected void <strong>onStart()</strong> {<br>      super.onStart();<br>      Log.d(msg, &quot;The onStart() event&quot;);<br>   }<br><br>   /** Called when the activity has become visible. */<br>   @Override<br>   protected void <strong>onResume()</strong> {<br>      super.onResume();<br>      Log.d(msg, &quot;The onResume() event&quot;);<br>   }<br><br>   /** Called when another activity is taking focus. */<br>   @Override<br>   protected void <strong>onPause()</strong> {<br>      super.onPause();<br>      Log.d(msg, &quot;The onPause() event&quot;);<br>   }<br><br>   /** Called when the activity is no longer visible. */<br>   @Override<br>   protected void <strong>onStop()</strong> {<br>      super.onStop();<br>      Log.d(msg, &quot;The onStop() event&quot;);<br>   }<br><br>   /** Called just before the activity is destroyed. */<br>   @Override<br>   public void <strong>onDestroy()</strong> {<br>      super.onDestroy();<br>      Log.d(msg, &quot;The onDestroy() event&quot;);<br>   }<br>}</pre><p>Let’s try to run our application, it will display Emulator window and you should see following log messages in <strong>LogCat</strong> window in Android studio.</p><pre>LogCat:</pre><pre>D/Android :: The onCreate() event<br>D/Android :: The onStart() event<br>D/Android :: The onResume() event</pre><p>Let’s try to click lock screen button on the Android emulator and it will generate following events messages in <strong>LogCat</strong> window in android studio.</p><pre>LogCat:</pre><pre>D/Android :: The onPause() event<br>D/Android :: The onStop() event</pre><p>Let’s again try to unlock your screen on the Android emulator and it will generate following events messages in <strong>LogCat</strong> window in Android studio.</p><pre>LogCat:</pre><pre>D/Android :: The onStart() event<br>D/Android :: The onResume() event</pre><p>Next, try to click back button on the left home button and it will generate following events messages in <strong>LogCat</strong> window in Android studio and this completes the Activity Lifecycle for an Android Application.</p><pre>LogCat:</pre><pre>D/Android :: The onPause() event<br>D/Android :: The onStop() event<br>D/Android :: The onDestroy() event</pre><p>This’s the end of Android Activity Lifecycle basis, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://www.w3schools.blog/android-tutorial">https://www.w3schools.blog/android-tutorial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c43a408959c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn To Use Git]]></title>
            <link>https://medium.com/@chauanh19981998/learn-to-use-git-f15b70871f1e?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/f15b70871f1e</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 04:17:11 GMT</pubDate>
            <atom:updated>2022-03-03T04:17:11.976Z</atom:updated>
            <content:encoded><![CDATA[<h4>Git Install</h4><p>You can download Git for free from the following website: <a href="https://git-scm.com/">https://www.git-scm.com/</a></p><h4>Using Git with Command Line</h4><p>To start using Git, we are first going to open up our Command shell.</p><p>For Windows, you can use Git bash, which comes included in Git for Windows. For Mac and Linux you can use the built-in terminal.</p><p>The first thing we need to do, is to check if Git is properly installed</p><pre>$ git --version <br>git version 2.30.2.windows.1</pre><h4>Configure Git</h4><p>Now let Git know who you are. This is important for version control systems, as each Git commit uses this information</p><pre>$ git config --global user.name &quot;anhc95&quot; <br>$ git config --global user.email &quot;anhc95@gmail.vn&quot;</pre><h4>Creating Git Folder</h4><p>Now, let’s create a new folder for our project</p><pre>$ mkdir myproject <br>$ cd myproject</pre><p>mkdir <strong>make</strong>s a <strong>new directory</strong>.</p><p>cd <strong>changes</strong> the <strong>current working directory</strong>.</p><p>Now that we are in the correct directory. We can start by initializing Git!</p><h4>Initialize Git</h4><p>Once you have navigated to the correct folder, you can initialize Git on that folder</p><pre>$ git init  <br>$ Initialized empty Git repository in /Users/user/myproject/.git/</pre><p>You just created your first Git Repository!</p><h3>Git Staging Environment</h3><p>One of the core functions of Git is the concepts of the Staging Environment, and the Commit.</p><p>As you are working, you may be adding, editing and removing files. But whenever you hit a milestone or finish a part of the work, you should add the files to a Staging Environment.</p><p><strong>Staged</strong> files are files that are ready to be <strong>committed</strong> to the repository you are working on. You will learn more about commit shortly.</p><p>For example, we are done working with index.html. So we can add it to the Staging Environment</p><pre>$ git add index.html</pre><p>The file should be <strong>Staged</strong>. Let’s check the status</p><pre>$ git status </pre><pre>On branch master  </pre><pre>No commits yet  </pre><pre>Changes to be committed:   <br>(use &quot;git rm --cached ...&quot; to unstage)     <br>new file: index.html</pre><p>Now the file has been added to the Staging Environment.</p><p>Using --all instead of individual filenames will stage all changes (new, modified, and deleted) files.</p><pre>$ git add --all</pre><pre>$ git status <br>On branch master  </pre><pre>No commits yet  <br>Changes to be committed:   <br>(use &quot;git rm --cached ...&quot; to unstage)         <br>            <br>new file:   index.html</pre><p>Now all files are added to the Staging Environment, and we are ready to do our first commit.</p><h4>Git Commit</h4><p>Since we have finished our work, we are ready move from stage to commit for our repo.</p><p>Adding commits keep track of our progress and changes as we work. Git considers each commit change point or &quot;save point&quot;. It is a point in the project you can go back to if you find a bug, or want to make a change.</p><p>When we commit, we should <strong>always</strong> include a <strong>message</strong>.</p><p>By adding clear messages to each commit, it is easy for yourself (and others) to see what has changed and when.</p><pre>$ git commit -m &quot;First release of Hello World!&quot; <br>[master (root-commit) 221ec6e] <br>First release of Hello World!  </pre><pre>1 files changed, 26 insertions(+)  <br><br>create mode 100644 index.html</pre><p>The commit command performs a commit, and the -m &quot;message&quot; adds a message.</p><p>The Staging Environment has been committed to our repo, with the message:<br>“First release of Hello World!”</p><h4>Git Help</h4><p>If you are having trouble remembering commands or options for commands, you can use Git help.</p><p>There are a couple of different ways you can use the help command in command line:</p><ul><li>git <em>command</em> -help - See all the available options for the specific command</li><li>git help --all - See all possible commands</li></ul><h4>New Git Branch</h4><p>Let add some new features to our index.html page.</p><p>We are working in our local repository, and we do not want to disturb or possibly wreck the main project.</p><p>So we create a new branch</p><pre>$ git branch hello-world</pre><p>Now we created a new branch called &quot;hello-world&quot;</p><p>Let’s confirm that we have created a new branch</p><pre>git branch   <br>hello-world<br>* master</pre><p>We can see the new branch with the name “hello-world”, but the * beside master specifies that we are currently on that branch.</p><p>checkout is the command used to check out a branch. Moving us <strong>from</strong> the current branch, <strong>to</strong> the one specified at the end of the command</p><pre>$ git checkout hello-world<br>Switched to branch &#39;hello-world&#39;</pre><p>Now we have moved our current workspace from the master branch, to the new branch . When we have made changes to a file and added a new file in the new branch (hello-world)</p><p>Now check the status of the current branch</p><pre>$ git status <br>On branch hello-world<br>Changes not staged for commit:   <br>(use &quot;git add ...&quot; to update what will be committed)   <br>(use &quot;git restore ...&quot; to discard changes in working directory)         modified:   index.html <br> <br>Untracked files:   <br>(use &quot;git add ...&quot; to include in what will be committed)         img_hello_world.jpg  </pre><pre>no changes added to commit <br>(use &quot;git add&quot; and/or &quot;git commit -a&quot;)</pre><p>Using $ git add -all will <strong>Stage</strong> all changed (new, modified, and deleted) files.</p><p>Check the status of the branch</p><pre>$ git status <br>On branch hello-world</pre><pre>Changes to be committed:   <br>(use &quot;git restore --staged ...&quot; to unstage)    <br> <br>new file: img_hello_world.jpg    <br>modified: index.html</pre><p>We will commit them to the branch</p><pre>$ git commit -m &quot;Added image to Hello World&quot; <br>[hello-world 0312c55] Added image to Hello World <br>1 files changed, 1 insertion(+) <br>create mode 100644 img_hello_world.jpg</pre><p>Now we have a new branch, that is different from the master branch.</p><h4>Merge Git</h4><p>We have the hello-world ready, and so let’s merge the master and hello-world branches (In case, The conflict at 2 branches has been fixed ).</p><pre>$ git commit -m &quot;merged with hello-world&quot;              <br>[master e0b6038] merged with hello-world</pre><p>And delete the hello-world branch</p><pre>$ git branch -d hello-world<br>Deleted branch hello-world(was 1f1584e).</pre><p>This’s the end of basics Git, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://git-scm.com/docs/gittutorial">Git - gittutorial Documentation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f15b70871f1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Version Control Systems ?]]></title>
            <link>https://medium.com/@chauanh19981998/what-are-version-control-systems-bbcf42d51ef?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbcf42d51ef</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 16:26:57 GMT</pubDate>
            <atom:updated>2022-03-01T16:26:57.723Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are Version Control Systems ?</h3><h4><strong>What ‘s “version control system”?</strong></h4><p>Version control systems are a category of software tools that helps in recording changes made to files by keeping a track of modifications done to the code.</p><h4><strong>Why Version Control system is so Important?</strong></h4><p>As we know that a software product is developed in collaboration by a group of developers they might be located at different locations and each one of them contributes in some specific kind of functionality/features. So in order to contribute to the product, they made modifications in the source code (either by adding or removing). A version control system is a kind of software that helps the developer team to efficiently communicate and manage (track) all the changes that have been made to the source code along with the information like who made and what change has been made. It not only keeps source code organized but also improves productivity by making the development process smooth.</p><p><strong>Benefits of the version control system:</strong></p><p><strong>a) </strong>Enhances the project development speed by providing efficient collaboration.</p><p><strong>b)</strong> Leverages the productivity, expedite product delivery, and skills of the employees through better communication and assistance.</p><p><strong>c) </strong>Reduce possibilities of errors and conflicts meanwhile project development through traceability to every small change.</p><p><strong>d) </strong>Member<strong> </strong>or contributor of the project can contribute from anywhere irrespective of the different geographical locations through this <strong>VCS </strong>.<br><strong>e)</strong> For each different contributor of the project a different working copy is maintained and not merged to the main file unless the working copy is validated. A most popular example is <strong>Git, Helix core, Microsoft TFS,</strong></p><p><strong>f) </strong>Helps in recovery in case of any disaster or contingent situation,</p><p><strong>g) </strong>Informs us about Who, What, When, Why changes have been made.</p><p><strong>Use of Version Control System:</strong></p><ul><li><strong>A repository:</strong> It can be thought of as a database of changes. It contains all the edits and historical versions (snapshots) of the project.</li><li><strong>Copy of Work (sometimes called as checkout):</strong> It is the personal copy of all the files in a project. You can edit to this copy, without affecting the work of others and you can finally commit your changes to a repository when you are done making your changes.</li></ul><h4>Why use version control?</h4><p>Software is developed to solve a user problem. Increasingly, these solutions have many different forms (e.g. mobile, embedded, SaaS) and run a variety of environments, such as cloud or Edge. As organizations accelerate delivery of their software solutions through DevOps, controlling and managing different versions of application artifacts - from code to configuration and from design to deployment - becomes increasingly difficult.</p><p>Version control facilitates coordination, sharing, and collaboration across the entire software development team. Version control software enables teams to work in distributed and asynchronous environments, manage changes and versions of code and artifacts, and resolve merge conflicts and related anomalies.</p><h4>Which is the best version control software?</h4><p>There are several source code management options that can help your team streamline development. The three most well-known options are Git, SVN, and Mercurial</p><p><strong>Git</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*co_1qORNdM0PI1nvCp7Iig.png" /></figure><p>Git is the most popular option and has become synonymous with “source code management.” Git is an open source distributed system that is used for software projects of any size, making it a popular option for startups, enterprise, and everything in between.</p><p><strong>Subversion</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*FUIwm5uStL7Qe8ZegpY_-w.png" /></figure><p>SVN is a widely adopted centralized version control system. This system keeps all of a project’s files on a single codeline making it impossible to branch, so it’s easy to scale for large projects. It’s simple to learn and features folder security measures, so access to subfolders can be restricted.</p><p><strong>Mercurial</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*sALM0j-VJkI_v7nZmsZBgw.png" /></figure><p>Mercurial is a distributed version control system that offers simple branching and merging capabilities. The system enables rapid scaling and collaborative development, with an intuitive interface. The flexible command line interface enables users to begin using the system immediately.</p><p>This’s the end of Version control system, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><ul><li><a href="https://en.wikipedia.org/wiki/Version_control">Version control - Wikipedia</a></li><li><a href="https://about.gitlab.com/topics/version-control/">What is version control?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbcf42d51ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Context]]></title>
            <link>https://medium.com/@chauanh19981998/android-context-44f64bce5197?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/44f64bce5197</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 16:17:38 GMT</pubDate>
            <atom:updated>2022-03-01T16:17:38.544Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>What is Context in Android ?</strong></h4><p>Its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application) You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class).</p><p>Few important points about the context:</p><ul><li>It is the context of the current state of the application.</li><li>It can be used to get information regarding the activity and application.</li><li>It can be used to get access to resources, databases, and shared preferences, and etc.</li><li>Both the Activity and Application classes extend the Context class.</li></ul><p>Context is almost everywhere in Android Development and it is the most important thing in Android Development, so we must understand to use it correctly.</p><h4><strong>Types of Context in Android</strong></h4><p>There are mainly two types of context are available in Android.</p><ol><li>Application Context</li><li>Activity Context</li></ol><p>The Overall view of the App hierarchy looks like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*PVDc52vKKEFZ-Jpe54eh_Q.png" /></figure><p>It can be seen in the above image that in “Sample Application”, nearest Context is Application Context. In “Activity1” and “Activity2”, both Activity Context (Here it is Activity1 Context for Activity1 and Activity2 Context for Activity2) and Application Context. The nearest Context to both is their Activity Context only.</p><p><strong>Application Context</strong></p><p>It is an instance that is the singleton and can be accessed in activity via getApplicationContext(). This context is tied to the lifecycle of an application. The application context can be used where you need a context whose lifecycle is separate from the current context or when you are passing a context beyond the scope of activity. Some use cases of Application Context are:</p><ul><li>If it is necessary to create a singleton object</li><li>During the necessity of a library in an activity</li></ul><p><strong>getApplicationContext():</strong></p><p>It is used to return the context which is linked to the Application which holds all activities running inside it. When we call a method or a constructor, we often have to pass a context and often we use <strong>“this”</strong> to pass the activity context or <strong>“getApplicationContext”</strong> to pass the application context. This method is generally used for the application level and can be used to refer to all the activities. For example, if we want to access a variable throughout the android app, one has to use it via <strong>getApplicationContext()</strong>.</p><p><strong>Activity Context</strong></p><p>This context is available in an activity. This context is tied to the lifecycle of an activity. The activity context should be used when you are passing the context in the scope of an activity or you need the context whose lifecycle is attached to the current context. The method of invoking the Activity Context is <strong>getContext()</strong>.</p><p>Some use cases of Activity Context are:</p><ul><li>The user is creating an object whose lifecycle is attached to an activity.</li><li>Whenever inside an activity for UI related kind of operations like toast, dialogue, etc.,</li></ul><p><strong>getContext():</strong></p><p>It returns the Context which is linked to the Activity from which it is called. This is useful when we want to call the context from only the current running activity.</p><h4><strong>Example</strong></h4><p>This example demonstrates how do I display context in an android textView.</p><p>Add the following code to res/layout/activity_main.xml.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout   xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>   xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>   android:layout_width=&quot;match_parent&quot;<br>   android:layout_height=&quot;match_parent&quot;<br>   android:id=&quot;@+id/linearLayout&quot;<br>   android:orientation=&quot;vertical&quot;<br>   android:padding=&quot;16sp&quot;<br>   tools:context=&quot;.MainActivity&quot;&gt;<br>&lt;/LinearLayout&gt;</pre><p>Add the following code to src/MainActivity.java</p><pre>import android.graphics.Color;<br>import android.support.v7.app.AppCompatActivity;<br>import android.os.Bundle;<br>import android.widget.LinearLayout;<br>import android.widget.TextView;<br>public class MainActivity extends AppCompatActivity {<br>   @Override<br>   public void onCreate(Bundle savedInstanceState) {<br>      super.onCreate(savedInstanceState);<br>      setContentView(R.layout.activity_main);<br>      LinearLayout linearLayout = findViewById(R.id.linearLayout);<br>      TextView textViewContext = new        TextView(getApplicationContext());<br>      textViewContext.setTextSize(30);<br>      textViewContext.setText(&quot;Application Context&quot;);<br>      textViewContext.setTextColor(Color.RED);<br>      TextView textViewActivityContext = new TextView(this);<br>      textViewActivityContext.setTextSize(30);<br>      textViewActivityContext.setText(&quot;Activity Context&quot;);<br>      linearLayout.addView(textViewContext);<br>      linearLayout.addView(textViewActivityContext);<br>   }<br>}</pre><p>Add the following code to androidManifest.xml</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; package=&quot;app.com.example&quot;&gt;<br>   &lt;application<br>      android:allowBackup=&quot;true&quot;<br>      android:icon=&quot;@mipmap/ic_launcher&quot;<br>      android:label=&quot;@string/app_name&quot;<br>      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;<br>      android:supportsRtl=&quot;true&quot;<br>      android:theme=&quot;@style/AppTheme&quot;&gt;<br>      &lt;activity android:name=&quot;.MainActivity&quot;&gt;<br>         &lt;intent-filter&gt;<br>            &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br>            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>         &lt;/intent-filter&gt;<br>      &lt;/activity&gt;<br>   &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>Run this code and see the result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*s7zrIiTK0992a019kzrjJA.png" /></figure><p>This’s the end of Android Context, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><p>Reference</p><p><a href="https://stackoverflow.com/questions/3572463/what-is-context-on-android">What is &#39;Context&#39; on Android?</a></p><p><a href="https://developer.android.com/reference/android/content/Context">https://developer.android.com/reference/android/content/Context</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44f64bce5197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Fragment]]></title>
            <link>https://medium.com/@chauanh19981998/android-fragment-2a5d5477cd57?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a5d5477cd57</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 04:30:57 GMT</pubDate>
            <atom:updated>2022-03-01T04:30:57.653Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s Fragment ?</h4><p>Android Fragment is the part of activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screen inside one activity.</p><p>Android fragment lifecycle is affected by activity lifecycle because fragments are included in activity.</p><p>Each fragment has its own life cycle methods that is affected by activity life cycle because fragments are embedded in activity.</p><p>The <strong>FragmentManager</strong> class is responsible to make interaction between fragment objects.</p><h4>Android Fragment Lifecycle</h4><p>The lifecycle of android fragment is like the activity lifecycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*AnFvlBEIDCVEBb9zUh_MNQ.jpeg" /><figcaption><strong>Fragment Lifecycle</strong></figcaption></figure><h4>Android Fragment Lifecycle Methods</h4><ul><li><strong>onAttach(Activity)</strong> it is called only once when it is attached with activity.</li><li><strong>onCreate(Bundle)</strong> It is used to initialize the fragment.</li><li><strong>onCreateView(LayoutInflater, ViewGroup, Bundle)</strong> creates and returns view hierarchy.</li><li><strong>onActivityCreated(Bundle)</strong> It is invoked after the completion of onCreate() method.</li><li><strong>onStart()</strong> makes the fragment visible.</li><li><strong>onResume()</strong> makes the fragment interactive.</li><li><strong>onPause()</strong> is called when fragment is no longer interactive.</li><li><strong>onStop()</strong> is called when fragment is no longer visible.</li><li><strong>onDestroyView()</strong> allows the fragment to clean up resources.</li><li><strong>onDestroy()</strong> allows the fragment to do final clean up of fragment state.</li><li><strong>onDetach()</strong> It is called immediately prior to the fragment no longer being associated with its activity.</li></ul><h4>Android Fragment Example</h4><p>Let’s have a look at the simple example of android fragment.</p><p><strong>File: activity_main.xml</strong></p><pre><strong>&lt;?xml</strong> version=”1.0&quot; encoding=”utf-8&quot;<strong>?&gt;</strong></pre><pre><strong>&lt;LinearLayout</strong>    xmlns:android=”http://schemas.android.com/apk/res/android&quot;</pre><pre>xmlns:app=”http://schemas.android.com/apk/res-auto&quot;</pre><pre>xmlns:tools=”http://schemas.android.com/tools&quot;</pre><pre>android:layout_width=”fill_parent”</pre><pre>android:layout_height=”fill_parent”</pre><pre>tools:context=”example.java.com.fragmentexample.MainActivity”<strong>&gt;</strong></pre><pre><strong>&lt;fragment</strong></pre><pre>android:id=”@+id/fragment1&quot;</pre><pre>android:name=”example.java.com.fragmentexample.Fragment1&quot;</pre><pre>android:layout_width=”0px”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:layout_weight=”1&quot;</pre><pre><strong>/&gt;</strong></pre><pre><strong>&lt;fragment</strong></pre><pre>android:id=”@+id/fragment2&quot;</pre><pre>android:name=”example.java.com.fragmentexample.Fragment2&quot;</pre><pre>android:layout_width=”0px”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:layout_weight=”1&quot;</pre><pre><strong>/&gt;</strong></pre><pre><strong>&lt;/LinearLayout&gt;</strong></pre><p><strong>File: fragment_fragment1.xml</strong></p><pre><strong>&lt;FrameLayout</strong> xmlns:android=”http://schemas.android.com/apk/res/android&quot;</pre><pre>xmlns:tools=”http://schemas.android.com/tools&quot;</pre><pre>android:layout_width=”match_parent”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:background=”#F5F5DC”</pre><pre>tools:context=”example.java.com.fragmentexample.Fragment1&quot;<strong>&gt;</strong></pre><pre>&lt;! — TODO: Update blank fragment layout →</pre><pre><strong>&lt;TextView</strong></pre><pre>android:layout_width=”match_parent”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:text=”@string/hello_blank_fragment” <strong>/&gt;<br></strong></pre><pre><strong>&lt;/FrameLayout&gt;</strong></pre><p><strong>File: fragment_fragment2.xml</strong></p><pre><strong>&lt;FrameLayout</strong> xmlns:android=”http://schemas.android.com/apk/res/android&quot;</pre><pre>xmlns:tools=”http://schemas.android.com/tools&quot;</pre><pre>android:layout_width=”match_parent”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:background=”#F0FFFF”</pre><pre>tools:context=”example.java.com.fragmentexample.Fragment2&quot;<strong>&gt;</strong></pre><pre>&lt;! — TODO: Update blank fragment layout →</pre><pre><strong>&lt;TextView</strong></pre><pre>android:layout_width=”match_parent”</pre><pre>android:layout_height=”match_parent”</pre><pre>android:text=”@string/hello_blank_fragment” <strong>/&gt;</strong></pre><pre><strong>&lt;/FrameLayout&gt;</strong></pre><p><strong>File: MainActivity.java</strong></p><pre><strong>package</strong> example.java.com.fragmentexample;</pre><pre><strong>import</strong> android.support.v7.app.AppCompatActivity;</pre><pre><strong>import</strong> android.os.Bundle;</pre><pre><strong>public</strong> <strong>class</strong> MainActivity <strong>extends</strong> AppCompatActivity {</pre><pre>@Override</pre><pre><strong>protected</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {</pre><pre><strong>          super</strong>.onCreate(savedInstanceState);</pre><pre>          setContentView(R.layout.activity_main);</pre><pre>     }</pre><pre>}</pre><p><strong>File: Fragment1.java</strong></p><pre><strong>package</strong> example.java.com.fragmentexample;</pre><pre><strong>import</strong> android.os.Bundle;</pre><pre><strong>import</strong> android.support.v4.app.Fragment;</pre><pre><strong>import</strong> android.view.LayoutInflater;</pre><pre><strong>import</strong> android.view.View;</pre><pre><strong>import</strong> android.view.ViewGroup;</pre><pre><strong>public</strong> <strong>class</strong> Fragment1 <strong>extends</strong> Fragment {</pre><pre>@Override</pre><pre><strong>public</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {</pre><pre><strong>       super</strong>.onCreate(savedInstanceState);</pre><pre>}</pre><pre>@Override</pre><pre><strong>public</strong> View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {</pre><pre>   // Inflate the layout for this fragment</pre><pre><strong>   return</strong> inflater.inflate(R.layout.fragment_fragment1, container,   <strong>false</strong>);</pre><pre>   }</pre><pre>}</pre><p><strong>File: Fragment2.java</strong></p><pre><strong>package</strong> example.java.com.fragmentexample;</pre><pre><strong>import</strong> android.os.Bundle;</pre><pre><strong>import</strong> android.support.v4.app.Fragment;</pre><pre><strong>import</strong> android.view.LayoutInflater;</pre><pre><strong>import</strong> android.view.View;</pre><pre><strong>import</strong> android.view.ViewGroup;</pre><pre><strong>public</strong> <strong>class</strong> Fragment2 <strong>extends</strong> Fragment {</pre><pre>@Override</pre><pre><strong>public</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {</pre><pre><strong>       super</strong>.onCreate(savedInstanceState);</pre><pre>}</pre><pre>@Override</pre><pre><strong>public</strong> View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {</pre><pre>    // Inflate the layout for this fragment</pre><pre><strong>    return</strong> inflater.inflate(R.layout.fragment_fragment2, container, <strong>false</strong>);</pre><pre>  }</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*odv5tfqaagA0hNoMyXpTnA.png" /><figcaption><strong>Output</strong></figcaption></figure><p>This’s the end of Android Fragment, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><h4>Reference</h4><p><a href="https://developer.android.com/guide/fragments">https://developer.android.com/guide/fragments</a></p><p><a href="https://freetuts.net/fragment-trong-android-2154.html">Fragment trong Android - Freetuts</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a5d5477cd57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Using Android Studio Debugger]]></title>
            <link>https://medium.com/@chauanh19981998/debugging-using-android-studio-debugger-38b2d80901aa?source=rss-db55cd48c1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/38b2d80901aa</guid>
            <dc:creator><![CDATA[Châu Anh]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 04:22:44 GMT</pubDate>
            <atom:updated>2022-03-01T04:22:44.933Z</atom:updated>
            <content:encoded><![CDATA[<h4>About debugging</h4><p>Debugging is the process of finding and fixing errors (bugs) or unexpected behavior in your code. All code has bugs, from incorrect behavior in your app, to behavior that excessively consumes memory or network resources, to actual app freezing or crashing.</p><p>Bugs can result for many reasons:</p><ul><li>Errors in your design or implementation.</li><li>Android framework limitations (or bugs).</li><li>Missing requirements or assumptions for how the app should work.</li><li>Device limitations (or bugs)</li></ul><p>Use the debugging, testing, and profiling capabilities in Android Studio to help you reproduce, find, and resolve all of these problems. Those capabilities include:</p><ul><li>The Android monitor (logcat)</li><li>The Android Studio debugger</li><li>Testing frameworks such as JUnit or Espresso</li></ul><p>In this blog you’ll learn how to debug your app with the Android Studio debugger, set and view breakpoints, step through your code, and examine variables.</p><h4>Enable debugging</h4><p>Before you can begin debugging, you need to prepare as follows:</p><ul><li><strong>Enable debugging on your device: </strong>If you’re using the emulator, this is enabled by default. But for a connected device, you need to enable debugging in the device developer options.</li><li><strong>Run a debuggable build variant: </strong>You must use a build variant that includes debuggable true in the build configuration. Usually, you can just select the default &quot;debug&quot; variant that&#39;s included in every Android Studio project (even though it&#39;s not visible in the build.gradle file). But if you define new build types that should be debuggable, you must add `debuggable true` to the build type</li></ul><pre>android {<br>    buildTypes {<br>        customDebugType {<br>            debuggable true<br>            ...<br>        }<br>    }<br>}</pre><h4>Start debugging</h4><p>You can start a debugging session as follows:</p><ol><li>Set some breakpoints in the app code.</li><li>In the toolbar, select a device to debug your app on from the target device drop-down menu.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*H6w76wkKBJjRJcM2deSaPg.png" /></figure><p>In the toolbar, click <strong>Debug</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/50/0*GFR8ifhitVt_j8Xn.png" /></figure><p>Android Studio builds an APK, signs it with a debug key, installs it on your selected device, then runs it and opens the Debug window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*ztWWG-1Hg2jmj4hhtOHOqg.png" /></figure><h4>Resume or Stop Debugging</h4><p>To resume executing an app after debugging it, select <strong>Run &gt; Resume Program</strong> or click the Resume icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/0*DmV6TpAbODMPOjUZ.png" /></figure><p>To stop debugging your app, select <strong>Run &gt; Stop</strong> or click the Stop icon in the toolbar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/0*U3IJfzqHQf4kgElh.png" /></figure><h4><strong>Add breakpoints</strong></h4><p>To add a breakpoint to a line in your code, use these steps:</p><ol><li>Locate the line of code where you want to pause execution.</li><li>Click in the left gutter of the editor window at that line, next to the line numbers. A red dot appears at that line, indicating a breakpoint.</li><li>You can also use <strong>Run &gt; Toggle Line Breakpoint</strong> or Control-F8 (Command-F8 on OS X) to set a breakpoint at a line.</li></ol><p>If your app is already running, you don’t need to update it to add the breakpoint.</p><p>When your code execution reaches the breakpoint, Android Studio pauses execution of your app. You can then use the tools in the Android debugger to view the state of the app and debug that app as it runs.</p><h4>Stepping through code</h4><p>After your app’s execution has stopped because a breakpoint has been reached, you can execute your code from that point one line at a time with the Step Over, Step Into, and Step Out functions.</p><p>To use any of the step functions:</p><ol><li>Begin debugging your app. Pause the execution of your app with a breakpoint. Your app’s execution stops, and the debugger shows the current state of the app. The current line is highlighted in your code.</li><li>Click the <strong>Step Over </strong>icon, select <strong>Run &gt; Step Over,</strong> or type F8. Step Over executes the next line of the code in the current class and method, executing all of the method calls on that line and remaining in the same file.</li><li>Click the <strong>Step Into </strong>icon, select <strong>Run &gt; Step Into,</strong> or type F7. Step Into jumps into the execution of a method call on the current line (versus just executing that method and remaining on the same line).</li><li>Click the <strong>Step Out </strong>icon, select <strong>Run &gt; Step Out,</strong> or type Shift-F8. Step Out finishes executing the current method and returns to the point where that method was called.</li><li>To resume normal execution of the app, select <strong>Run &gt; Resume Program</strong> or click the Resume icon.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/1*znnAdDrS9ywG_RGBZ8_JAw.png" /><figcaption><strong>Step Over</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/1*XtfhYMPk6gcwHx5pIJb_Wg.png" /><figcaption><strong>Step Into</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/1*SZPW3nLquDeHzkIYne-5Gg.png" /><figcaption><strong>Step Out</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/1*HOkCn_rgaO1TGcWFmdVKHg.png" /><figcaption><strong>Resume Program</strong></figcaption></figure><h4>Viewing execution stack frames</h4><p>The <strong>Frames</strong> view of the debugger window allows you to inspect the execution stack and the specific frame that caused the current breakpoint to be reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/0*xW55VCkhhlGN-Ucf.png" /></figure><p>Clicking a line for a frame in the Frames view opens the associated source in the editor and highlights the line where that frame was initially executed. The Variables and Watches views also update to reflect the state of the execution environment when that frame was last entered.</p><h4>Inspecting and modifying variables</h4><p>The <strong>Variables</strong> view of the debugger window allows you to inspect the variables available at the current stack frame when the system stops your app on a breakpoint. Variables that hold objects or collections such as arrays can be expanded to view their components.</p><p>The <strong>Variables</strong> pane also allows you to evaluate expressions on the fly using static methods and/or variables available within the selected frame.</p><p>If the Variables view is not visible, click the <strong>Restore Variables View</strong> icon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/0*Amgkmx5RSbKXkqhS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/0*QI5u2x2m1Jcb5vy1.png" /></figure><p>To modify variables in your app as it runs:</p><ol><li>Right-click any variable in the Variables view, and select <strong>Set Value</strong>. You can also use F2.</li><li>Enter a new value for the variable and type Return. The value you enter must be of the appropriate type for that variable, or Android Studio returns a “type mismatch” error.</li></ol><p>This’s the end of debugging in Android Studio, If you want to see more, You can get link at reference.</p><p>Thank you for reading, have a nice day ❤.</p><p>Reference</p><p><a href="https://developer.android.com/studio/debug#groovy">https://developer.android.com/studio/debug#groovy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38b2d80901aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>