<?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 Prasan P on Medium]]></title>
        <description><![CDATA[Stories by Prasan P on Medium]]></description>
        <link>https://medium.com/@prasanwrites?source=rss-b54f2a5a37c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ScyAcXRZUdpgG-BLVC0qCA.jpeg</url>
            <title>Stories by Prasan P on Medium</title>
            <link>https://medium.com/@prasanwrites?source=rss-b54f2a5a37c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:45:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prasanwrites/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[Using reCAPTCHA in Android with Safetynet API and Retrofit]]></title>
            <link>https://medium.com/android-nuggets/using-recaptcha-in-android-with-safetynet-api-and-retrofit-b5e7cc6fd132?source=rss-b54f2a5a37c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5e7cc6fd132</guid>
            <category><![CDATA[safetynet-api]]></category>
            <category><![CDATA[android-recaptcha]]></category>
            <category><![CDATA[recaptcha]]></category>
            <category><![CDATA[safety-net]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Prasan P]]></dc:creator>
            <pubDate>Wed, 05 Sep 2018 05:24:50 GMT</pubDate>
            <atom:updated>2018-09-09T16:05:19.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using reCAPTCHA in Android with SafetyNet API, LiveData, ViewModel and Retrofit</h3><p>Away with the bots!</p><p>Google’s <a href="https://developer.android.com/training/safetynet/">SafetyNet API</a> provides a collection of services that help shield Android applications from a plethora of hazards that plague the online world in this day and age, viz. compromised devices, security threats, harmful websites, phishing attacks, malware apps and bots.</p><p>Among the many services that SafetyNet API offers is the ability to verify the authenticity (human/bot) of a user via a reCAPTCHA in order to prevent applications, especially ones where one need to perform user registrations, from being inundated with bots.</p><blockquote>I had a really hard time searching the Internet trying to find an article that is updated with the latest SafetyNet API, LiveData, ViewModel and Retrofit. So once I finished with the code, I decided to write one myself.</blockquote><p>The <a href="https://developer.android.com/training/safetynet/recaptcha">SafetyNet reCAPTCHA API</a> has a 2-step verification process</p><ol><li>A device-side verification with the Site Key generating a user response token.</li><li>A server-side verfication using the response token from 1 and the Secret Key</li></ol><p>In this article, we go through the steps that adds a reCAPTCHA into an Android app and validates the user.</p><h4>Step 1: Terms &amp; Conditions</h4><p>T&amp;Cs of using Google APIs for the fine-print-junkie</p><p><a href="https://developers.google.com/terms/">Google APIs Terms of Service | Google Developers</a></p><h4>Step 2: Register App &amp; Get Site &amp; Secret Keys</h4><p>In order to use SafetyNet reCaptcha API, first we register the Android application on the <a href="https://g.co/recaptcha/androidsignup">reCaptcha Android sign-up site</a>. We enter a label and the app’s applicationID in the form below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bm283nIUM3blmsJHbr_zug.png" /></figure><p>One we fill out the form and click on <strong>Register</strong> we will be provided with a Site Key and a Secret Key. The Site Key is used to verify the request while the Secret Key verifies the user response via a service call. It is advised to securely store the keys in your application.</p><h4>Step 3: Setup The Module build.gradle</h4><p>In our module level build.gradle we add a few dependencies required to perform the entire verifcation process.</p><p>First, the <strong>play-services-safetynet</strong> dependency.</p><pre>implementation &#39;com.google.android.gms:play-services-safetynet:15.0.1&#39;</pre><p>Also, the <strong>Retrofit </strong>dependencies for response verification</p><pre>implementation &#39;com.squareup.retrofit2:retrofit:2.3.0&#39;<br>implementation &#39;com.squareup.retrofit2:converter-gson:2.3.0&#39;</pre><p><strong><em>Optional:</em></strong> I used Android Architecture Component’s <strong>LiveData </strong>and <strong>ViewModel</strong> in my sample app for which I added the below dependency.</p><pre>implementation &quot;android.arch.lifecycle:extensions:$lifecycle_version&quot;</pre><h4>Step 4: Request Verification Using Site Key</h4><p>Wherever in the Android application we would perform the reCAPTCHA verifcation, we have to instantiate the SafetNet API and add a success and a failure listener and invoke the <em>verifyWithRecaptcha </em>method.</p><pre>SafetyNet.<em>getClient</em>(MainActivity.this).verifyWithRecaptcha(**SITE KEY GOES HERE**)<br>        .addOnSuccessListener(new SuccessListener())<br>        .addOnFailureListener(new FailureListener());</pre><p>Instead of using anonymous inner classes I chose to use concrete implementations. Below is the FailureListener class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe5ce0c0beea8c6e30fdc2472b24b992/href">https://medium.com/media/fe5ce0c0beea8c6e30fdc2472b24b992/href</a></iframe><p>We will see how our SuccessListener class looks in the next step</p><h4>Step 5: Response Verification Using Secret Key</h4><p>If the device-side verfication goes well, we need to perform a secondary verification via a webservice. For that purpose, we need to send a POST request to the URL: <a href="https://www.google.com/recaptcha/api/siteverify">https://www.google.com/recaptcha/api/siteverify</a> with following three parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Un5NksQGk07qgdKz8QnaCw.jpeg" /><figcaption>Query parameters for response verification</figcaption></figure><blockquote>For the purpose of simplicity, we will skip sending the <em>remoteip </em>parameter</blockquote><p>This task is performed by our SuccessListener class which is an implementation of the onSuccessListener interface provided by SafetyNet API.</p><p>Before we see the class, let’s set up our Retrofit to perform the network call required for the verification. In order to set up the service we need a Retrofit API interface as shown below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4d0a78b2a30806d966f7f628c213cd8/href">https://medium.com/media/c4d0a78b2a30806d966f7f628c213cd8/href</a></iframe><p><strong>Note:</strong> Even though the service is a POST request, the parameters have to be passed as query parameters more commonly seen in GET requests</p><p>Next, we set up the service. I have used a Repository pattern and a ViewModel for modularity purposes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98ee3fd6246dc4a7da5954be02fe69dd/href">https://medium.com/media/98ee3fd6246dc4a7da5954be02fe69dd/href</a></iframe><p>The RecaptchaVerificationResponse is our response POJO class that gson uses to de-serialize the JSON response from the service call</p><pre>{<br>  &quot;success&quot;: true|false,<br>  &quot;challenge_ts&quot;: timestamp,  // timestamp of the challenge load <br>  &quot;apk_package_name&quot;: string, // the package name of the app<br>  &quot;error-codes&quot;: [...]        // optional<br>}</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/233612e35a310c4b9ba4998dec854e3c/href">https://medium.com/media/233612e35a310c4b9ba4998dec854e3c/href</a></iframe><p>And finally, below is our SuccessListener which performs the entire token response verification and observes our ViewModel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8cfedca329c5725340c90e0ca12f83/href">https://medium.com/media/6e8cfedca329c5725340c90e0ca12f83/href</a></iframe><p>And thats it! If done correctly, the device and the service verification will complete successfully and the user will be verified to be not a bot.</p><blockquote>Github repo for the app built for this tutorial</blockquote><p><a href="https://github.com/prasannajeet/reCaptchaSampleAndroid">prasannajeet/reCaptchaSampleAndroid</a></p><p>Liked the article? Well slap on those claps!</p><p>Questions? -&gt; <a href="https://twitter.com/Prasannajeet">Twitter</a></p><p><a href="https://medium.com/@prasannajeet">Prasannajeet Pani - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5e7cc6fd132" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-nuggets/using-recaptcha-in-android-with-safetynet-api-and-retrofit-b5e7cc6fd132">Using reCAPTCHA in Android with Safetynet API and Retrofit</a> was originally published in <a href="https://medium.com/android-nuggets">Android Nuggets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using The Navigation Architecture Component in Android Jetpack (Kotlin) — Now updated to 1.0.0]]></title>
            <link>https://medium.com/android-nuggets/using-the-navigation-architecture-component-in-android-jetpack-kotlin-48d4167ec9e5?source=rss-b54f2a5a37c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/48d4167ec9e5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-navigation]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android-architecture]]></category>
            <dc:creator><![CDATA[Prasan P]]></dc:creator>
            <pubDate>Mon, 03 Sep 2018 18:39:05 GMT</pubDate>
            <atom:updated>2019-06-22T16:15:15.168Z</atom:updated>
            <content:encoded><![CDATA[<h4>Android’s answer to Storyboards in iOS</h4><h4>Table of Contents</h4><ul><li><a href="https://medium.com/p/48d4167ec9e5#9f6f">Introduction</a></li><li><a href="https://medium.com/p/48d4167ec9e5#5a3e">Setup</a></li><li><a href="https://medium.com/p/48d4167ec9e5#2f9a">Adding Action</a></li><li><a href="https://medium.com/p/48d4167ec9e5#adda">Adding Arguments</a></li><li><a href="https://medium.com/p/48d4167ec9e5#096c">Creating The XML Layouts</a></li><li><a href="https://medium.com/p/48d4167ec9e5#2db0">Some Kotlin Code To Get It All Working</a></li><li><a href="https://medium.com/p/48d4167ec9e5#9445">Conclusion</a></li></ul><h4><strong>Note</strong>: The GitHub codebase provided at the end of the article has now been updated to use Navigation 1.0.0. The diff commit for the same can be found <a href="https://github.com/prasannajeet/android-navigation-example/commit/be42ae583fec4a645f6fd7f948e2032ef56fd5d6">here</a>. The article in process of being updated to reflect the changes.</h4><h3>Introduction</h3><p>Android application development has taken a huge stride over the last few years. I started programming Android applications back in the days when writing the entire code in Activities was considered the **right** way of doing things. Since then, we have had Fragments come along, then came the idea of MVP/MVVM/MVI architectures, Reactive programming, Event Bus, Clean Architecture etc.</p><p>Google itself has decided to promote the Model-View-ViewModel approach to write applications in and has advocated it as part of their with <a href="https://developer.android.com/topic/libraries/architecture/">Android Architecture Components</a> framework which was further expanded into <a href="https://developer.android.com/jetpack/">Android Jetpack</a> during Google I/O 2018. Among the concepts introduced include ViewModel, LiveData, Room Database, WorkManager and Navigation. This article explains the last.</p><blockquote><strong><em>FYI</em></strong><em>: If you would like to get a good understanding of how Android Jetpack and Architecture Components work, </em><a href="https://github.com/googlesamples/android-sunflower"><em>here is a project called Sunflower currently under active development by Google and written in Kotlin</em></a><em> that I would highly recommend.</em></blockquote><blockquote>Find the Github repo of an expanded sample app I created using the steps mentioned below</blockquote><p><a href="https://github.com/prasannajeet/android-navigation-example">prasannajeet/android-navigation-example</a></p><p>The core aspect of the Navigation Component lies in the application’s <em>navigation graph</em>. To understand what a navigation graph is we have to understand the concept of <em>destinations</em>. As per Google:</p><p><em>A destination is any place you can navigate to in your app. While destinations are usually Fragments representing specific screens, the Navigation Architecture Component supports other destination types:</em></p><ul><li><em>Activities</em></li><li><em>Navigation graphs and subgraphs — when the destination is a graph or subgraph, you navigate to the starting destination of that graph or subgraph</em></li><li><a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-add-new.html"><em>Custom destination types</em></a></li></ul><p>A set of destinations comprise your application’s <em>navigation graph. </em>In addition to destinations, a navigation graph has connections between destinations called <em>actions.</em></p><p>Below image shows you the destinations in the sample app I ended up creating for myself. We will be creating a much simpler 2 fragment navigation graph in this tutorial</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfFbdq6NMKY5G0C5NMW5Vg.png" /><figcaption>Navigation Graph for my Sample app</figcaption></figure><p>Enough talk. Lets see some code!</p><h3>Setup</h3><p><strong>Step 0:</strong></p><p><strong>You need to have Android Studio 3.2 RC or above in order to work with any Android Jetpack components including Navigation (</strong><a href="https://developer.android.com/studio/preview/"><strong>download</strong></a><strong>). Also, for the purposes of this tutorial, knowledge of Kotlin is a must.</strong></p><p><strong>Step 1:</strong></p><p>Create a new Android project, add a blank activity and let the gradle build finish</p><p><strong>Step 2:</strong></p><p>Add the following dependencies to your existing <strong>app/build.gradle</strong> file and perform a gradle sync. This should go in your <strong>dependencies{}</strong> block</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0417574a495dd9b3d62797ff10421038/href">https://medium.com/media/0417574a495dd9b3d62797ff10421038/href</a></iframe><p>Additionally, in order to support passing of values between the views involved in a navigation we would need to add the typesafe gradle plugin.</p><p>Add the <strong>navigation-safe-args-gradle-plugin</strong> in the project level <strong>build.gradle</strong>’s <strong>dependencies{} </strong>tag. The file should look something like this in its entirety.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b495df9b65c7337cc6c1dc99e12f53d5/href">https://medium.com/media/b495df9b65c7337cc6c1dc99e12f53d5/href</a></iframe><p>Then in the<strong> app/build.gradle</strong> we have to add the following gradle plugin before the <strong>android{}</strong> block</p><pre>apply plugin: &#39;androidx.navigation.safeargs&#39;</pre><p><strong>Step 3:</strong></p><p>For implementing Navigation, Android has introduced a new resource type called <strong>Navigation</strong>. Right click on the <strong>res</strong> directory and choose <strong>New -&gt; Android resource file</strong>. Choose a title for the file and select <strong>Navigation</strong> from the <strong>Resource type</strong> dropdown. It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7LsaoxNYidAwBaGJOCknA.png" /><figcaption>Adding a navigation graph file</figcaption></figure><p>Once you have created the navigation xml file it will look something like this</p><pre><strong>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;navigation xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot; android:id=&quot;@+id/welcome_nav_graph&quot;&gt;<br><br>&lt;/navigation&gt;</strong></pre><p><strong>Step 4:</strong></p><p>If you haven’t already, go to <strong>File — Settings (Android Studio — Preferences in Mac)</strong> and click on <strong>Experimental </strong>on the left menu. Select <strong>Enable Navigation Editor</strong> on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0lmG_-dpenxQ0D8ktQO3Q.png" /><figcaption>Enable Navigation Editor</figcaption></figure><p><strong>Step 5:</strong></p><p>In you navigation graph xml file go to <strong>Design </strong>view and click on the <strong>New Destination</strong> icon and it should show something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*jP3tQk7yQCbA4D_Swr1Rsg.png" /><figcaption>Create blank destination</figcaption></figure><p>We will create two fragments here by clicking on the <strong>Create Blank Destination</strong> button. <strong>MainFragment</strong> and <strong>DestinationFragment</strong>. Once you have created both the fragments here your navigation xml file will look like this</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;navigation 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:id=&quot;@+id/welcome_nav_graph&quot;<br>    <strong>app:startDestination=&quot;@id/mainFragment&quot;</strong>&gt;<br><br>    <strong>&lt;fragment<br>        android:id=&quot;@+id/mainFragment&quot;<br>        android:name=&quot;com.praszapps.mysamplenavapp.MainFragment&quot;<br>        android:label=&quot;fragment_main&quot;<br>        tools:layout=&quot;@layout/fragment_main&quot; /&gt;<br>    &lt;fragment<br>        android:id=&quot;@+id/destinationFragment&quot;<br>        android:name=&quot;com.praszapps.mysamplenavapp.DestinationFragment&quot;<br>        android:label=&quot;fragment_destination&quot;<br>        tools:layout=&quot;@layout/fragment_destination&quot; /&gt;</strong><br>&lt;/navigation&gt;</pre><p>And your design view should look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmbB8Kac8JZCK67ogUNpGA.png" /></figure><p>The home icon on mainFragment signifies that its the s<strong>tarting point of your navigation</strong>. This usually is the fragment/activity that shows first when you launch the app.</p><p>In the next section, we will setup navigation from mainFragment to destinationFragment and pass a String value between them</p><h3>Adding Action</h3><p>In order for the framework to understand which destination it needs to go to from the source you have to specify an action. You will have to add the action tag inside your <strong>source/home</strong> fragment from where the navigation is to be performed.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;navigation 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:id=&quot;@+id/welcome_nav_graph&quot;<br>    app:startDestination=&quot;@id/mainFragment&quot;&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/mainFragment&quot;<br>        android:name=&quot;com.praszapps.mysamplenavapp.MainFragment&quot;<br>        android:label=&quot;fragment_main&quot;<br>        tools:layout=&quot;@layout/fragment_main&quot; &gt;<br>        <strong>&lt;action<br>                   android:id=&quot;@+id/action_mainFragment_to_destinationFragment&quot;<br>            app:destination=&quot;@id/destinationFragment&quot; /&gt;</strong><br>    &lt;/fragment&gt;<br>    &lt;fragment<br>        android:id=&quot;@+id/destinationFragment&quot;<br>        android:name=&quot;com.praszapps.mysamplenavapp.DestinationFragment&quot;<br>        android:label=&quot;fragment_destination&quot;<br>        tools:layout=&quot;@layout/fragment_destination&quot; /&gt;<br>&lt;/navigation&gt;</pre><h3>Adding Arguments</h3><p>Let’s say you are passing a name from your MainFragment into DestinationFragment and in the latter you show a message “Welcome $name”. I order to get the name from the source to the destination we need to pass it as an argument. You may add multiple such arguments.</p><p>Setting an Argument type in turns results in invoking that Fragment using the value passes as a Bundle argument. We will see how in the next section.</p><p>In the navigation XML, add an &lt;argument/&gt; tag to the <strong>destination</strong> fragment. There are 3 attributes an argument can take</p><ol><li><strong>android:name</strong>— The identifier for the argument</li><li><strong>app:argType</strong>— What datatype it is. Currently it supports <strong>inferred, integer, string, reference</strong></li><li><strong>android:defaultValue (optional)</strong> — A default value that the recieving fragment will get in case the source fragment does not pass any value</li></ol><p>With that done, your navigation XML file will now look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5cd24f989da7b5d96bf5f6347501578/href">https://medium.com/media/c5cd24f989da7b5d96bf5f6347501578/href</a></iframe><p>And thus the navigation is setup, the framework knows what is the source, the destination and what data is to be passed along during navigation. Now let’s go and create a simple UI and stitch it all up with some Kotlin code</p><h3>Creating The XML Layouts</h3><p>We will create a very basic UI wherein we have an EditText and a Button in the MainFragment where we enter our name. Upon button click, we pass the name from MainFragment to DestinationFragment to be shown as “Welcome $name”.</p><p>Below is how my layouts look, feel free to copy it over to your project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2292c06805733b3cde02fad53d07f9b/href">https://medium.com/media/f2292c06805733b3cde02fad53d07f9b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61cf27946ce8e8657eb08e83b47491dc/href">https://medium.com/media/61cf27946ce8e8657eb08e83b47491dc/href</a></iframe><p>And finally the Activity layout where will add the MainFragment</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0503a16daad54ab03ad9d519e654904/href">https://medium.com/media/b0503a16daad54ab03ad9d519e654904/href</a></iframe><h3>Some Kotlin Code To Get It All Working</h3><p><strong>Step 1: MainActivity</strong></p><p>Add the MainFragment to the MainActivity in the onCreate() function. We will use <strong>NavHostFragment.create()</strong> to get our <strong>NavHostFragment </strong>which we then pass onto the <strong>FragmentTransaction </strong>to invoke the Fragment</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2625d2ceb2671840a2ddb1b172f0afca/href">https://medium.com/media/2625d2ceb2671840a2ddb1b172f0afca/href</a></iframe><p><strong>setPrimaryNavigationFragment </strong>function is added to set up the backstack navigation of the Fragment notifying MainFragment as the host.</p><p><strong>Step 2: MainFragment</strong></p><p>In the MainFragment, we need to perform the action on the button click to navigate to DetailFragment taking along with it the name that’s entered in the EditText.</p><p>In the <strong>onViewCreated </strong>method of the Fragment, we get the action object that we added in the navigation XML under &lt;action&gt; tag.</p><pre>val action = MainFragmentDirections.actionMainFragmentToDestinationFragment()</pre><p>In this action we will add the name that’s entered in our EditText. This value will then be passed into the DestinationFragment as an argument</p><pre>action.setNameToShow(enterName.<em>text</em>.toString())</pre><p>Finally, we invoke the NavController to perform the navigation</p><pre><em>findNavController</em>().navigate(action)</pre><p>I have added input validation alongwith the above code and my MainFragment looks something like this at the end of the step</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14def04bc0d9a0ff1366b9cf8fe491f5/href">https://medium.com/media/14def04bc0d9a0ff1366b9cf8fe491f5/href</a></iframe><p><strong>Step 3: DestinationFragment</strong></p><p>In the DestinationFragment we will need to retrieve the argument passed and set it as the text in the TextView we have placed in the layout</p><p>We will get the arguments for the class navigated to by using the {ClassName}Args.from() function. For Example, in this case we get the name that was passed from MainFragment in this fashion.</p><pre>val name = DestinationFragmentArgs.fromBundle(<em>arguments</em>).<em>nameToShow</em></pre><p>Here <em>nameToShow </em>is the argument name that we had set in navigation XML file.</p><p>The final DestinationFragment class looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b468224525a6150d04d01593ff247b0/href">https://medium.com/media/9b468224525a6150d04d01593ff247b0/href</a></iframe><h3>Conclusion</h3><p>And that’s it! Once everything is set up, just run the app in the emulator and you would see the Navigation Framework work its magic for yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WzfOap4W7aPCSVhPKfGnug.gif" /></figure><p>Like the article? Well slap on those claps!!!</p><p>Cheers!!!</p><p><a href="https://medium.com/@prasannajeet">Prasannajeet Pani - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48d4167ec9e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-nuggets/using-the-navigation-architecture-component-in-android-jetpack-kotlin-48d4167ec9e5">Using The Navigation Architecture Component in Android Jetpack (Kotlin) — Now updated to 1.0.0</a> was originally published in <a href="https://medium.com/android-nuggets">Android Nuggets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fix annoying Android Studio 3.1.x bug not showing preview for XML layouts?]]></title>
            <link>https://medium.com/android-nuggets/how-to-fix-android-studio-3-1-x-not-showing-preview-for-xml-layouts-34fc32e900f3?source=rss-b54f2a5a37c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/34fc32e900f3</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-layout]]></category>
            <category><![CDATA[layout]]></category>
            <dc:creator><![CDATA[Prasan P]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 19:19:18 GMT</pubDate>
            <atom:updated>2018-09-09T16:06:05.147Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Ever had to face the issue where you are trying to construct a layout in Android Studio 3.1.x and you saw something like this on your layout preview?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*82WKxf-YL6N0GJhZQV6j2A.png" /><figcaption>Android Studio layout preview shows no actual previews</figcaption></figure><p>Well, I hear you. I had to look around the Internet a lot and finally I found a <a href="https://stackoverflow.com/questions/50929640/android-studio-3-1-3-design-view-is-always-empty">StackOverflow solution</a> that helped me.</p><blockquote>All you had to do is go to <strong>styles.xml </strong>file and replace your parent theme from <strong><em>Theme.AppCompat.Light.DarkActionBar</em></strong> to <strong><em>Base.Theme.AppCompat.Light.DarkActionBar</em></strong></blockquote><p>And just like that, I got my layout preview to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YM8YcbZ1WCV4L8Yg4rrR4A.png" /><figcaption>Fixed!!!!</figcaption></figure><p>Its mighty annoying that Google hasn’t fixed this little bit of a kink on Android Studio in an update so far. But at least now we have a fix.</p><blockquote><em>Truth can only be found in one place: the code. — </em><a href="https://twitter.com/unclebobmartin?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor"><em>Robert. C. Martin</em></a><em>.</em></blockquote><p>Like the article? Well slap on those claps!!!</p><p>Cheers!!!</p><p><a href="https://medium.com/@prasannajeet">Prasannajeet Pani - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34fc32e900f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-nuggets/how-to-fix-android-studio-3-1-x-not-showing-preview-for-xml-layouts-34fc32e900f3">How to fix annoying Android Studio 3.1.x bug not showing preview for XML layouts?</a> was originally published in <a href="https://medium.com/android-nuggets">Android Nuggets</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>