<?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 Veronika Figura on Medium]]></title>
        <description><![CDATA[Stories by Veronika Figura on Medium]]></description>
        <link>https://medium.com/@vepetruskova?source=rss-5890ecf6f650------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VSq5CqY3y1Bb4CLK83ZIuw.png</url>
            <title>Stories by Veronika Figura on Medium</title>
            <link>https://medium.com/@vepetruskova?source=rss-5890ecf6f650------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:03:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vepetruskova/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[The New Android In-App Navigation]]></title>
            <link>https://medium.com/@vepetruskova/the-new-android-in-app-navigation-f7bfbe925b9?source=rss-5890ecf6f650------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7bfbe925b9</guid>
            <category><![CDATA[android-architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[navigation-drawer]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Veronika Figura]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 15:06:25 GMT</pubDate>
            <atom:updated>2018-09-04T15:06:25.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QocVcbGZ4MeJbTCZ" /><figcaption>“rood signage” by <a href="https://unsplash.com/@ernest_brillo?utm_source=medium&amp;utm_medium=referral">Ernest Brillo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>During the past few weeks I had time to dive into the Navigation Architecture Component that Google presented at this years Google I/O. It is a part of Android <a href="https://developer.android.com/jetpack/">Jetpack</a> and its main goal is to ease in-app navigation on Android.</p><p>I’m going to show you how navigation component can simplify your everyday Android stuff like navigating when clicking on adapter item or through navigation drawer.</p><p>I’ve also created a simple app in Kotlin where you’ll find everything mentioned in this article. So if you have trouble with something, you can look at the whole code at this <a href="https://github.com/laVepe/navigation-component-example">repo</a>.</p><h3>☝️ First things first</h3><p>If you’re completely new to Navigation component, you can go through <a href="https://proandroiddev.com/android-navigation-arch-component-a-curious-investigation-3e56e24126e1">this </a>post to learn how to create navigation graph with the use of Navigation editor. Or <a href="https://medium.com/google-developer-experts/android-navigation-components-part-1-236b2a479d44">this</a> post series to also help structure your app better. And it’s always good practice to look at the <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing">documentation</a>.</p><p>There’s also a <a href="https://codelabs.developers.google.com/codelabs/android-navigation/#0">codelab</a> which is a great way to start if you’re not familiar with this component but you want to learn by coding.</p><p>Ready? OK, let’s start by taking a closer look at the Navigation Component.</p><h3>Navigation Component main players</h3><p>Before diving into code we should have some knowledge about classes and interfaces that we’re going to work with. <a href="https://developer.android.com/reference/androidx/navigation/package-summary">Documentation</a> mentions three main components:</p><ul><li><strong>NavGraph — </strong>a collection of destinations. It can be inflated from layout file or created programmatically. You can have multiple navigation graphs in your application and they can be also nested.</li><li><strong>NavHost —</strong> an interface serving as a container that hosts the NavController.</li><li><strong>NavController — </strong>class managing navigation within NavHost by interacting with NavGraph.</li></ul><p>Other classes you’ll use include:</p><p><strong>NavHostFragment</strong> — implementation of NavHost for creating fragment destinations. It has its own NavController and navigation graph. Typically you would have one NavHostFragment per activity.</p><p><strong>Navigation — </strong>helper class for obtaining NavController instance and for connecting navigation to UI events like a button click.</p><p><strong>NavigationUI — </strong>class for connecting app navigation patterns like drawer, bottom navigation or actionbar with NavController.</p><h3>Let’s quickly refresh the basics</h3><p>Let’s say you’ve created navigation graph XML file and you’ve created a fragment in your activity layout file.</p><p>Now you have to set its name to NavHostFragment to indicate that this will be the place for switching destinations while navigating inside this activity. And you have to associate it with an existing navigation graph XML file.</p><p>The result should look something like this:</p><pre>&lt;fragment<br>    android:layout_width=”match_parent”<br>    android:layout_height=”match_parent”<br>    android:id=”@+id/nav_host”<br>    android:name=”androidx.navigation.fragment.NavHostFragment”<br>    app:navGraph=”@navigation/nav_graph”<br>    app:defaultNavHost=”true” //to intercept with system Back button<br> /&gt;</pre><p>If you want to see it done programmatically, see the <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#create_the_navhostfragment_programmatically">docs</a>.</p><p>To navigate between destinations(activities or fragments) you can use:</p><ul><li>target <strong>destination id</strong> e.g. navController.navigate(R.id.mainActivity)</li><li><strong>action id</strong> e.g. navController.navigate(R.id.actionDetail)</li></ul><p>If you don’t have NavController you can obtain it in multiple ways:</p><ul><li>in <strong>activity </strong>by getting NavHostFragment instance:</li></ul><pre>val host: NavHostFragment = supportFragmentManager<br>   .findFragmentById(R.id.nav_host) as NavHostFragment? ?: return<br>val navController = host.navController</pre><ul><li>in <strong>fragment </strong>or <strong>view </strong>by calling findNavController()</li><li>or by calling Navigation.findNavController(view) passing a <strong>view </strong>associated with NavController</li></ul><p>To <strong>go back </strong>to previous destination in graph use navController.navigateUp() method.</p><p>To hook up view to navigation use <strong>onClickListener</strong>:</p><pre>button.setOnClickListener { view -&gt;<br>  view.findNavController().navigate(R.id.actionDetail)<br>}</pre><p>or</p><pre>button.setOnClickListener(<br> Navigation.createNavigateOnClickListener(R.id.actionDetail,  bundle))</pre><p>where first parameter is action id or destination id and second is <strong>bundle </strong>for passing data between destinations. There’s also one argument version of this function when you don’t need to send data.</p><h3>Returning data to destination</h3><p>We know how to send data from first destination to second, but what about if we want to get some data back? When working with activities we would typically use startActivityForResult method and get the result in onActivityResult after second activity finishes. I searched if Navigation Component has something similar.</p><p>In <a href="https://issuetracker.google.com/issues/79672220">this</a> issue someone from Google recommended using a <strong>shared ViewModel</strong>. For activities we should probably continue using the old way, because you can’t share ViewModel between activities like you can with fragments.</p><p>Also Google is shifting more towards single activity per app approach and if community follows, getting result back from activity will be less common.</p><p>But if you want to share data between <strong>fragments</strong>, simply create a <strong>ViewModel scoped to activity</strong> and use it in both fragments. Then you have access to properties in ViewModel from both fragments.</p><p>If you need to imitate sending data when navigating back, you can use <strong>Event</strong> which is a wrapper class for data sent via LiveData. Event was created especially for <strong>one time consumable</strong> <strong>data </strong>like displaying SnackBar or Toast message. You can learn more about that in an <a href="https://medium.com/google-developers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150#f155">article</a> from <a href="https://medium.com/u/e0a4c9469bb5">Jose Alcérreca</a>.</p><h3>Simplifying drawer, ActionBar and bottom navigation</h3><p>Working with Navigation component saves you not just the boilerplate when writing fragment transactions but it’s very useful also when initializing <strong>navigation drawer</strong>.</p><p>No need to setup ActionBarDrawerToggle and NavigationItemSelectedListener<em> </em>anymore. It turns this pile of code:</p><pre>val toggle = ActionBarDrawerToggle(this, drawer_layout, null, R.string.navigation_drawer_open, R.string.navigation_drawer_close)<br>drawer_layout.addDrawerListener(toggle)<br>toggle.syncState()<br>toggle.isDrawerIndicatorEnabled = true</pre><pre>nav_view.setNavigationItemSelectedListener { menuItem -&gt;<br> when (menuItem.itemId) {<br>            R.id.nav_first -&gt; go somewhere…<br>            R.id.nav_second -&gt; go somewhere else…<br> }<br> menuItem.isChecked = true<br> drawer_layout.closeDrawer(Gravity.START)<br> true<br>}</pre><p>Into this:</p><pre>NavigationUI.setupWithNavController(nav_view, navController)</pre><pre>NavigationUI.setupActionBarWithNavController(this, navController, drawer_layout)</pre><p>Awesome, right?! 👍</p><p>For this to work, you need to match <strong>item ids</strong> in your drawer <strong>menu </strong>with <strong>destination ids</strong> in your navigation <strong>graph</strong>. So if you have fragment with id @+id/home_fragment, you need to use the same id for the corresponding menu item in drawer.</p><p>The second line in above code snippet sets hamburger menu icon in actionbar and connects it to drawer. Last thing to do is to override onSupportNavigateUp method so that click on the icon opens the drawer:</p><pre><strong>override fun </strong>onSupportNavigateUp() = NavigationUI.navigateUp(drawer_layout, <strong>navController</strong>)</pre><p>If you want to setup only <strong>actionbar</strong> use the same method with only two arguments:</p><pre>setSupportActionBar(toolbar)<br>NavigationUI.setupActionBarWithNavController(this, navController)</pre><p>If you use <strong>bottom navigation</strong> instead, just call:</p><pre>NavigationUI.setupWithNavController(bottom_nav, navController)</pre><h3>Navigating from adapter item</h3><p>Navigation component makes it easier to react to click events on items in RecyclerView. The old way would be to create a listener interface that the activity/fragment implements and pass its instance to adapter via constructor. Then pass it to ViewHolder so you can call the listener’s method inside item’s on click listener implementation.</p><p>With Navigation component you don’t need to create an interface nor pass a listener instance to adapter if you’re only interested in navigating to another screen. Just set onClickListener on item’s view as follows:</p><pre>view.setOnClickListener(<br>  Navigation.createNavigateOnClickListener(destination_or_action_id)<br>)</pre><p>If you want to also <strong>send </strong>some <strong>data</strong>,<strong> </strong>use two argument version of this method and pass data using safe args plugin (more about it <a href="https://medium.com/@vepetruskova/using-safe-args-plugin-current-state-of-affairs-41b1f01e7de8">here</a>).</p><pre>val actionDetail = HomeFragmentDirections.ActionDetail()<br>actionDetail.setTitle(item)<br>view.setOnClickListener {          <br>  Navigation.createNavigateOnClickListener(R.id.actionDetail,   actionDetail.<em>arguments</em>)<br>}</pre><h3>Conditional navigation</h3><p><a href="https://medium.com/u/536e0cf1483a">Maria Neumayer</a> described this well in her <a href="https://medium.com/a-problem-like-maria/a-problem-like-navigation-part-2-63e46a565d4b#e732">article</a>. To sum it up, this kind of navigation is useful when you have some <strong>condition </strong>that has to be met to navigate to target destination. Good example is a <strong>login screen</strong>.</p><p>Let’s say user wants to navigate from Home screen to Profile but hasn’t logged in yet. Instead of Profile, Login screen is shown. After a successful login user is taken to the Profile screen. If he navigates back, he should be taken straight to the Home screen. <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-conditional">Documentation</a> suggests that</p><blockquote>The Login destination should pop itself off the navigation stack after it returns to the Profile destination. Call the popBackStack() method when navigating back to the original destination.</blockquote><p>In case your login flow consists from multiple screens, you can use:</p><pre><em>findNavController</em>().popBackStack(R.id.<em>premium_flow</em>, true)</pre><p>Above example will pop all destinations in stack that came after the one specified in 1st parameter. Second parameter describes if the specified destination should be also popped from the stack.</p><p>If you’re implementing <strong>login flow </strong>using a <strong>separate activity</strong>, simply call activity.finish()<em> </em>before navigating from login to another activity.</p><p>This way the login activity won’t stay in the stack and navigating up won’t show it. This is useful also with <strong>onboarding flow </strong>at app launch, because you don’t want to let user return to it by pressing the back button.</p><h3>Common destinations and global actions</h3><p>Common destination is a screen to which can user navigate from multiple parts of the app. For such cases we can use <strong>global actions</strong>. Unlike normal actions, they are defined on the same level as destinations — inside the root element of graph called navigation. They have an <strong>id </strong>and <strong>target </strong>destination. Global action can be used to navigate to its target destination from any other destination in the same navigation graph (nested graph also).</p><p><strong><em>Note:</em></strong><em> When you define a global action you also have to provide </em>android:id<strong><em> </em></strong><em>to the navigation element.</em></p><pre>&lt;navigation android:id=&quot;@+id/main&quot; ...&gt;</pre><pre>&lt;action android:id=&quot;@+id/action_global&quot;<br>    app:destination=&quot;@id/detailFragment&quot;/&gt;</pre><pre>&lt;fragment<br>    android:id=&quot;@+id/detailFragment&quot;<br>    .../&gt;</pre><pre>&lt;/navigation&gt;</pre><h3>Nested navigation graphs</h3><p>As your app becomes more filled with features you may consider putting some destinations from your navigation graph to a <strong>nested </strong>graph. It’s basically a graph within your <strong>main/root </strong>graph. This is useful if you have a setup flow that consists from multiple screens or an onboarding flow.</p><p><a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#group">Creating</a> a nested graph is quite simple and can make your root graph look less complicated and easier to understand.</p><p>Also it enables you to <strong>reuse </strong>the nested flow in your app. That’s because a nested graph has an <strong>id </strong>which is used as the only access point for navigation from the root graph. You won’t be able to navigate to specific destination in nested graph from the root graph.</p><pre>&lt;navigation android:id=&quot;@+id/main&quot; ...&gt;</pre><pre>&lt;navigation android:id=&quot;@+id/premium_flow&quot;<br>    app:startDestination=&quot;@id/premiumStep1Fragment&quot;&gt;<br>    <br>    &lt;fragment <br>        android:id=&quot;@+id/premiumStep1Fragment&quot; .../&gt;</pre><pre>    &lt;fragment<br>        android:id=&quot;@+id/premiumStep2Fragment&quot; .../&gt;</pre><pre>    &lt;/navigation&gt;<br>&lt;/navigation&gt;</pre><p>As you can see, Navigation Component has a lot to offer. It enables us to write less boilerplate code when implementing things like Navigation Drawer and simplifies fragment transactions. It surely is a nice contribution to the Architecture Components family.</p><p>There are still some topics that I haven’t covered in this article. <strong>Deep linking</strong> is well described in <a href="https://medium.com/google-developer-experts/android-navigation-components-part-3-19554ec9ae83#3bd0">this article</a>. Navigation Component <strong>testing </strong>isn’t really covered in docs yet, but <a href="https://medium.com/u/536e0cf1483a">Maria Neumayer</a> covers it briefly <a href="https://medium.com/a-problem-like-maria/a-problem-like-navigation-e9821625a70e#f68d">here</a>.</p><p>If you have any suggestions or questions, feel free to leave a comment below. Don’t forget to leave 👏 if you liked the post. It will be appreciated. ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7bfbe925b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Safe args plugin - current state of affairs]]></title>
            <link>https://medium.com/@vepetruskova/using-safe-args-plugin-current-state-of-affairs-41b1f01e7de8?source=rss-5890ecf6f650------2</link>
            <guid isPermaLink="false">https://medium.com/p/41b1f01e7de8</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Veronika Figura]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 09:15:24 GMT</pubDate>
            <atom:updated>2019-04-06T13:44:33.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4uWVOpqFCR1gGpJTewhhA.jpeg" /><figcaption>photo from <a href="https://pixabay.com/en/lifeguard-on-duty-lifebelt-help-3590445/">https://pixabay.com/en/lifeguard-on-duty-lifebelt-help-3590445/</a></figcaption></figure><h3>Using Safe args plugin — current state of affairs</h3><p>Couple of days ago I started working with the new Navigation Component that was presented at <a href="https://www.youtube.com/watch?v=8GCXtCjtg40">this years Google I/O</a> and is part of <a href="https://developer.android.com/jetpack/">Android Jetpack</a>. While reading about it in official documentation, I stumbled upon a <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#Safe-args">section</a> about passing data between destinations using safe args Gradle plugin. As documentation states, safe args plugin</p><blockquote>generates simple object and builder classes for type-safe access to arguments specified for destinations and actions. Safe args is built on top of the Bundle.</blockquote><p>So I thought I’ll give it a try and share my findings. I’ll show you how to pass data using this plugin and also what types of data is supported.</p><p>❗️<strong><em> Note:</em></strong><em> At the time of writing most recent release of safe args Gradle plugin was </em><strong><em>alpha04</em></strong><em>. I’ll try to update this post when things change in future.</em></p><h3>Type-safe data passing</h3><p>Passing data using safe args plugin takes only a few steps. First you have to add a dependency to your project level gradle file:</p><pre>classpath <strong>&quot;android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha04&quot;</strong></pre><p>and apply plugin in module level gradle file:</p><pre>apply <strong>plugin</strong>: <strong>&quot;androidx.navigation.safeargs&quot;</strong></pre><p>Then you define the argument for target destination in your navigation graph (we assume you already defined at least two destinations in the graph).</p><p>This requires three parameters: argument <strong>name, type</strong> and <strong>default value</strong>. You can use right panel in design tab of navigation editor for that.</p><p>❗️ <strong><em>Note:</em></strong> When you select argument type it will generate this xml code: app:type=”string”. If you try to rebuild project, Android Studio will give you an <strong>error</strong>:</p><blockquote>The ‘type’ attribute used by argument ‘title’ is deprecated. Please change all instances of ‘type’ in navigation resources to ‘argType’.</blockquote><p>It’s self explanatory enough so you know that you should change it to app:argType=”string” manually in xml. It’s because in plugin alpha04 release they’ve changed it. There’s already an issue on issue tracker for this so it should be fixed in upcoming releases.</p><p>When you’re done, switch to text tab and you should see something like this in your destination:</p><pre>&lt;fragment ...&gt;<br>&lt;argument<br>    android:name=&quot;title&quot;<br>    android:defaultValue=&quot;null&quot;<br>    app:argType=&quot;string&quot; /&gt;<br>&lt;/fragment&gt;</pre><p>Rebuild project so that two necessary builder classes get generated. These java classes are then used to pass the value of the argument.</p><p>First class is used for inserting data. It has name after the direction from which you send data and ends with <strong>‘Directions’</strong> e.g. <em>HomeFragmentDirections</em>. Second one is used to retrieve data at target direction and its name ends with <strong>‘Args’</strong> e.g. <em>DetailFragmentArgs</em>.</p><p>If you look at the generated classes, you’ll see they’re using Bundle and properties matching the arguments defined in our xml. We can access these properties through getters and setters.</p><p>To send data from destination you need to obtain an instance of generated class which is named after <strong>action</strong> that you created for navigating to another destination (in this example it’s called <em>ActionDetail</em>). After that just insert your data using a setter method and pass <em>actionDetail</em> instance as a parameter in your <em>NavController.navigate</em> call.</p><pre>val actionDetail = HomeFragmentDirections.ActionDetail()<br>actionDetail.setTitle(item)<br>Navigation.findNavController(view).navigate(actionDetail)</pre><p>Receiving data in target destination depends on it being an activity or fragment. If you’re retrieving data in <strong>activity</strong> you would get the bundled data from <em>extras</em> in <em>onCreate </em>method:</p><pre>val username = MainActivityArgs.fromBundle(intent?.extras).username</pre><p>For retrieving data in <strong>fragment</strong> use <em>arguments</em> property in either <em>onCreate, onCreateView or onViewCreated</em> lifecycle methods:</p><pre>arguments?.let {<br>    val safeArgs = DetailFragmentArgs.fromBundle(it)<br>    val title = safeArgs.title<br>}</pre><p>And that’s all. You’ve successfully transferred your data using safe args.</p><h3>Supported data types</h3><p>When you add arguments using design tab of navigation editor it lets you pick from only three types: <strong>string, integer </strong>and<strong> reference</strong>.</p><p>But we come from the Bundle world where we could pass all kinds of primitive types and also Parcelable objects. So I was curious and tried to change value of app:argType to <strong>boolean</strong> manually in xml.</p><p>It worked without problems. Then I found this <a href="https://issuetracker.google.com/issues/79563966">issue</a> on issue tracker where people asked for support for more types. So it looks like they’ve already done it for <strong>boolean,</strong> <strong>long</strong> and <strong>float</strong>. Using <strong>char</strong> and <strong>double</strong> as an argument type didn’t work though. Compile error was: part ‘double’ is keyword.</p><p>Then I tried passing a <strong>reference</strong>. Reference takes integer value so I thought it was for passing resource ids and my assumption was quickly confirmed by comment I found in the same <a href="https://issuetracker.google.com/issues/79563966">issue</a>:</p><blockquote>An argument with a type of “reference” is a reference to an Android resource i.e., with values like @string/value in XML or R.string.value in code.</blockquote><p>There I’ve also learned that since safe args plugin alpha03 (I was using alpha04 at the time) it also supports <strong>Parcelable</strong>.</p><p>You should use @null as default value and you have to also add app:nullable=”true” to allow nullable types because arguments are considered non-null by default and Android Studio will give you an error.</p><p>Also on <a href="https://developer.android.com/jetpack/docs/release-notes">page</a> with release notes was mentioned you should use a <strong>fully qualified class</strong> name for app:argType. So I tried following:</p><pre>&lt;argument<br> android:name=”item”<br> android:defaultValue=”@null”<br> app:nullable=”true”<br> app:argType=”com.vepe.navigation.model.Item” /&gt;</pre><p>Where Item is a simple data class in my model layer implementing Parcelable interface. If you’re not familiar with @Parcelize annotation, look <a href="https://proandroiddev.com/parcelable-in-kotlin-here-comes-parcelize-b998d5a5fcac#70a6">here</a>.</p><pre>@Parcelize<br><strong>data class </strong>Item(<strong>val index</strong>: Int, <strong>val title</strong>: String, <strong>val value</strong>: Double): Parcelable</pre><p>❗️ <strong><em>Note: </em></strong><em>You have to use a full class name. Using </em>app:argType=”Item”<em> will result in compile error because generated classes won’t be able to find and import your class.</em></p><h3>Conclusion</h3><p>It looks like safe args plugin currently supports more types than Android Studio 3.2 lets you know about. That’s understandable of course, since the studio is still in beta (beta5 at the time of writing). I guess they’ll update the Navigation editor UI to match this in future release.</p><p>But it’s nice to know that we’re already able to pass values of type long, float, boolean and also Parcelable objects and not just integer, string and reference.</p><p>📢 <strong><em>Update:</em></strong><em> Since the release of plugin version </em><strong><em>1.0.0-alpha08</em></strong><em> you can now pass also Serializable objects, enum values and arrays of primitive types and Parcelables.</em></p><pre><strong>enum class </strong>Category {<br>    <strong>CLOTHES</strong>, <strong>SHOES</strong>, <strong>ACCESSORIES</strong>, <strong>BAGS</strong>, <strong>UNDEFINED<br></strong>}</pre><p><em>You can specify the default value to be used directly from your enum class:</em></p><pre>&lt;argument<br>    android:name=&quot;category&quot;<br>    android:defaultValue=&quot;UNDEFINED&quot;<br>    app:argType=&quot;com.vepe.navigation.model.Category&quot;/&gt;</pre><p><em>For passing </em><strong><em>arrays</em></strong><em> of values define argument type for primitive types as follows:</em></p><pre>app:argType=&quot;integer[]&quot;</pre><p><em>And similarly for arrays of Parcelables:</em></p><pre>app:argType=&quot;com.vepe.navigation.model.Item[]&quot;</pre><p>📢📢 <strong><em>2nd update: </em></strong><em>Most recent release of plugin version </em><strong><em>1.0.0-alpha10</em></strong><em> (and </em><strong><em>1.0.0-alpha11</em></strong><em>, which is a hotfix release for the previous one) bring Kotlin users nice ways to write less code while using safe args plugin.</em></p><p><em>From now on Kotlin users can </em><strong><em>lazily </em></strong><em>get arguments using </em>by navArgs()<em> property delegate. For e.g. in the past I accessed username in my activity using fromBundle method.</em></p><pre>username = MainActivityArgs.fromBundle(intent?.extras).username</pre><p><em>Using mentioned </em><strong><em>property delegate</em></strong><em> and specifying expected Args type you can now retrieve your arguments during variable declaration:</em></p><pre>private val mainActivityArgs by navArgs&lt;MainActivityArgs&gt;()<br><br>// later in code access properties from args<br>username = mainActivityArgs.username</pre><p><em>Other nice improvement is you can generate Kotlin code by applying plugin </em>&#39;androidx.navigation.safeargs.kotlin&#39;<em> instead of </em>&#39;androidx.navigation.safeargs&#39;<em> in your app or other module gradle file.</em></p><p><em>There are some breaking changes related to this. Generated </em>Direction<em> and </em>NavDirections <em>classes (such as my ActionDetail class) no longer have a public constructor. Because of that you can no longer pass data through safe args the old way:</em></p><pre>HomeFragmentDirections.ActionDetail().setItem(item)</pre><p><em>You should only be interacting with the </em><strong><em>generated static methods</em></strong><em>. Name of method matches name of the action class. For the previous example this means using generated </em>actionDetail()<em> method which takes item as an argument:</em></p><pre>HomeFragmentDirections.actionDetail(item)</pre><p><em>For the complete list of new features and changes look </em><a href="https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0-alpha11"><em>here</em></a><em>. You can find up-to-date examples of using safe args in </em><a href="https://github.com/laVepe/navigation-component-example"><em>my navigation repo</em></a><em>.</em></p><p>That’s all for now. I hope you find information in this post useful. If you have any suggestions or questions, feel free to leave a comment below. 😉</p><p>Also this is my first post so every single clap will be really appreciated. 👏❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41b1f01e7de8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>