<?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 Alex Vainshtein on Medium]]></title>
        <description><![CDATA[Stories by Alex Vainshtein on Medium]]></description>
        <link>https://medium.com/@Alex.v?source=rss-e0c584e50880------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tEp9P9wBnZE1aCm2hPwD7Q.jpeg</url>
            <title>Stories by Alex Vainshtein on Medium</title>
            <link>https://medium.com/@Alex.v?source=rss-e0c584e50880------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:16:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Alex.v/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[Running Jetpack Compose on Windows 10]]></title>
            <link>https://medium.com/@Alex.v/running-jetpack-compose-on-windows-10-954738828f0b?source=rss-e0c584e50880------2</link>
            <guid isPermaLink="false">https://medium.com/p/954738828f0b</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[jetpack]]></category>
            <dc:creator><![CDATA[Alex Vainshtein]]></dc:creator>
            <pubDate>Sun, 30 Jun 2019 14:29:38 GMT</pubDate>
            <atom:updated>2019-06-30T14:45:22.542Z</atom:updated>
            <content:encoded><![CDATA[<p>I was excited when the new UI toolkit was introduced at Google IO 2019, and i wanted to try it straight away. But to my disappointment, it still in an early-exploration, pre-alpha stage, and there is no library that i can simply add to my project to test it.</p><p>Following the documentation on Jetpack Compose i learned, that to try it i need to set up the toolchain for AndroidX development, and check out the source code of android.x. But to my disappointment, Google allowing it only on Linux or Mac OS (but not on Windows).</p><p>So i started to search, how can i still do it on Windows 10. After a lot of attempts i was finally able to get the source code and run Jetpack Compose on Windows 10.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*8UpcdZ1K09N_9FK2YHC60g.png" /></figure><h3>The Steps</h3><ol><li><strong>Install Windows Subsystem for Linux</strong></li></ol><ul><li>Open PowerShell as Administrator.</li><li>Run: “Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux”.</li><li>Restart your computer when prompted.</li></ul><p>2.<strong> Install Ubuntu</strong></p><ul><li>Open the Microsoft Store and find Ubuntu.</li><li>Install Ubuntu.</li><li>Launch Ubuntu and follow the instructions.</li></ul><p>3. <strong>Checking out the code</strong></p><ul><li>Install repo</li></ul><pre>mkdir ~/bin<br>PATH=~/bin:$PATH<br>curl https://storage.googleapis.com/git-repo-downloads/repo &gt; ~/bin/repo<br>chmod a+x ~/bin/repo</pre><ul><li>Configure Git with your real name and email address.</li></ul><pre>git config — global user.name “Your Name”<br>git config — global user.email “you@example.com”</pre><ul><li>Create a directory for your checkout (it can be any name)</li></ul><pre>mkdir androidx-master-dev<br>cd androidx-master-dev</pre><ul><li>Use repo command to initialize the repository.</li></ul><pre>repo init -u <a href="https://android.googlesource.com/platform/manifest">https://android.googlesource.com/platform/manifest</a> -b androidx-master-dev</pre><ul><li>Now your repository is set to pull only what you need for building and running AndroidX libraries. Download the code (and grab a coffee while we pull down 6GB):</li></ul><pre>repo sync -j8 -c</pre><p>You will use this command to sync your checkout in the future — it’s similar to git fetch.</p><p>4. <strong>Install VcXsrv Windows X Server</strong></p><p>To run graphical Linux applications on Bash on Ubuntu on Windows 10 we need to install <a href="https://sourceforge.net/projects/vcxsrv/"><strong>VcXsrv</strong></a></p><ul><li>After installation launch <strong>XLaunch, </strong>follow the instructions(keep the defaults).</li><li>To start the required version of Android Studio, you need to run the studiow command from the /ui subfolder</li></ul><pre>cd path/to/checkout/frameworks/support/ui/<br>./studiow</pre><p>Now Android Studio should be running, and you can start playing with Jetpack Compose (try running ui-demos module).</p><blockquote><strong>Note: If you encountered this error: </strong><strong>Startup Error: Unable to detect graphics environment<br>Try to run this command:<br></strong>export DISPLAY=:0.0</blockquote><blockquote><strong><em>Note</em>: Because we are running Android Studio inside VcXsrv Windows X Server, the Android Studio will be running slower.</strong></blockquote><p>If you have trouble running emulator from this version of Android Studio, try to launch emulator from your regular Android Studio, and the run the application on it.</p><p><strong>Example Application Running on Emulator on Windows 10:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcrcuuxHz_oE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcrcuuxHz_oE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcrcuuxHz_oE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9155ee0fdcf4ae683c8f3ca77883557d/href">https://medium.com/media/9155ee0fdcf4ae683c8f3ca77883557d/href</a></iframe><h3><strong>Links:</strong></h3><p><strong>Jetpack Compose: </strong><a href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/README.md">https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/README.md</a></p><p><strong>Android Jetpack:</strong><br> <a href="https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md">https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md</a></p><p><strong>Windows Subsystem for Linux Installation Guide for Windows 10:</strong><br> <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">https://docs.microsoft.com/en-us/windows/wsl/install-win10</a></p><p><strong>Ubuntu App Installation:</strong><br> <a href="https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0">https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0</a></p><p><strong>VcXsrv Windows X Server:</strong><br> <a href="https://sourceforge.net/projects/vcxsrv/">https://sourceforge.net/projects/vcxsrv/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=954738828f0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Navigation Architecture Component]]></title>
            <link>https://medium.com/@Alex.v/android-navigation-architecture-component-25b5a7aab8aa?source=rss-e0c584e50880------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b5a7aab8aa</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Alex Vainshtein]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 03:37:11 GMT</pubDate>
            <atom:updated>2018-06-05T04:42:55.163Z</atom:updated>
            <content:encoded><![CDATA[<p>From the first moment that fragments were released (back in 2011), developers debated which application design should be used, whether the app should contain many activities with few fragments, or many fragments with few activities, or a combination of both.<br>Each developer would choose suitable architecture makes sense for him. Additionally developers had to deal with variety of navigation problems inherent in the platform, such as what will happen if user clicks the ‘Back’ button? Which screen should the user return to? And if the user came to this screen from a different app? From notification? From deep-link?</p><p>All this changed couple of weeks ago, at Google IO 2018, Android team decided to make it easier for developers to handle app navigation. They released a new component, <strong>Navigation Architecture Component</strong>, which is part of the “JetPack” package. This component should help developers implement app navigation faster and better.<br>Android team suggests that activity should be just an entry point to the application, and all the screen should be fragments, namely <strong>Single Activity App.</strong></p><p><strong>So how do we start?</strong> <br>First thing you need to download Android Studio 3.2 Canary(currently the latest build is 15).<br><a href="https://developer.android.com/studio/preview/">https://developer.android.com/studio/preview/</a><br>The new android Studio contains navigation editor with visual implementation of app navigation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPe93-NWXAili2anuyel4A.png" /></figure><p>Then we need to add the new navigation library (currently as alpha release)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5837e623bf9b1595767385eacf305f6c/href">https://medium.com/media/5837e623bf9b1595767385eacf305f6c/href</a></iframe><p>Now we will create new resource directory of type ‘navigation’ (under ‘res’ folder)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*ZKoOhpcqcXdRso72FhSRxg.png" /></figure><p>Let’s create a navigation graph file inside the navigation directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*SqoUwuAoFAa1zYLmhKsreA.png" /></figure><p>The newly created file contains 2 tabs, similar to the familiar Layout editor: Design - contains visual navigation editor and Text- xml structured file.<br>Now, let’s add some fragments to our navigation editor. If we click on add button, we can choose to create a blank fragment or select an existing fragment (or activity) from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*zzQElEKLpvIfBGyIT6Kdpg.png" /></figure><p>After adding a fragment, the xml file will be updated accordingly</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e109b427dcfc856ab8ef9f5b1e38070/href">https://medium.com/media/3e109b427dcfc856ab8ef9f5b1e38070/href</a></iframe><p>You will notice that fragment ui preview is unavailable. This can be fixed easily by adding this line inside fragment element inside xml</p><pre>tools:layout=”@layout/fragment_topics_list”</pre><p>The root element contains the id of the fragment that will act as the start destination. It can be easily changed from xml or from navigation editor by selecting the desired fragment and clicking on ‘Set Start Destination’ button on right-click menu.</p><p>Now, let’s connect some destinations. Hover over the right side of your origin fragment. You will see a circle- click it and drag the line toward your next destination fragment. Congratulations! You created an ‘Action’. This action will navigate you from origin fragment to destination fragment. The new navigation xml will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bed951dcdcfa445a5d9665e1e7e87480/href">https://medium.com/media/bed951dcdcfa445a5d9665e1e7e87480/href</a></iframe><p>The action contains an id and destination.</p><p>Now, to start using our new navigation, we need to change our activity. <br>Inside our activity layout we will add NavHostFragment</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1753c02a5012e0cba6f86f6253ef8361/href">https://medium.com/media/1753c02a5012e0cba6f86f6253ef8361/href</a></iframe><p>Notice the app:defaultNavHost=”true” attribute: this attribute ensures your NavHostFragment intercepts the system Back button.<br>Inside your activity you also need to overwrite the onSupportNavigateUp() method.</p><pre>override fun onSupportNavigateUp()<br> = NavHostFragment.findNavController(nav_host_fragment).navigateUp()</pre><p>For navigation we need to call</p><pre>view.findNavController().navigate(R.id.someAction)</pre><p>The ‘navigate()’ method accepts the id of an action or a destination(it can also accept bundle with parameters, more about passing parameters later)</p><p>For buttons you can also use createNavigateOnClickListener()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e29d6874a8b8b8fe531271f7fc1c44f/href">https://medium.com/media/1e29d6874a8b8b8fe531271f7fc1c44f/href</a></iframe><p>createNavigateOnClickListener() accepts an action or destination id.</p><p>If you want to navigate to some destination and to remove the origin from back stack, you can set ‘Clear Task’ to true for desired action in ‘Launch Options’ section inside attribute panel(or set app:clearTask=”true”, inside action element in navigation graph xml).</p><p>You can change the action’s ‘Pop To’ behavior from attribute panel(or from xml app:popUpTo=”@+id/connectionFragment”). This way, when user will click back, he will be navigated to connectionFragment instead of the original destination.</p><p>To support toolbar up icon action, and title based on destination, you should add inside your activity</p><pre>NavigationUI.setupActionBarWithNavController(this, NavHostFragment.findNavController(nav_host_fragment))</pre><p><em>The toolbar titles will be changed accordingly to fragments ‘label’ attribute inside navigate editor/xml.</em></p><p>If you want to tie menu/bottom navigation/drawer navigation to specific navigation destination, this can be done easily by setting the item id same as destination id. For example if we have destination fragment with id=signInFragment, then the menu item should look like this</p><pre>&lt;item<br>    android:id=&quot;@+id/signInFragment&quot;<br>    android:icon=&quot;@drawable/ic_check_black_24dp&quot;<br>    android:title=&quot;@string/navigation_sign_in&quot; /&gt;</pre><p>And we need to connect between them using a static method from NavigationUI class inside your activity</p><pre><br>setupWithNavController(navigation, findNavController(nav_host_fragment))</pre><p><strong>Passing data between fragments<br></strong>We have 2 ways to pass data between fragments. The first one is straight forward, pass a ‘Bundle’ with arguments to ‘navigate()’ or ‘createNavigateOnClickListener()’ method, in the destination fragment just call ‘getArguments()’ and retrieve your data.</p><p>The second way is a type-safe way, to use this way we need to use gradle plugin called ‘safeargs’ that generates simple object and builder classes for type-safe access to arguments specified for destinations and actions, in your build.gradle file add the next line</p><pre>apply plugin: &quot;androidx.navigation.safeargs&quot;</pre><p>In navigation editor click + in Arguments section of attributes panel on the right for your destination fragment, double click on name, enter an argument name, then click tab to move to next field, select desired type(currently type-safe way supports only integers and strings, but in the future it should support all the types that bundle can accept), then click tab again and set a default value (default value allows this argument to behave like optional parameter).<br>If you look at the navigation editor xml, you will notice that new element is added to your destination fragment</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa6a239074d2b8108ec3dab7791e3d0b/href">https://medium.com/media/aa6a239074d2b8108ec3dab7791e3d0b/href</a></iframe><p>After build or make project, there is a new class generated internally for origin fragment that have actions to destination fragment with arguments, this class name constructed from origin fragments name and appended with word ‘Directions’</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76a1d1e7ed7c3cd099c7f597297b2069/href">https://medium.com/media/76a1d1e7ed7c3cd099c7f597297b2069/href</a></iframe><p>And now, in order to pass data to destination fragment, we need to use action with arguments</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/357afe74f33107c26d235616c64ed095/href">https://medium.com/media/357afe74f33107c26d235616c64ed095/href</a></iframe><p>Because we set default value for argument ‘title’, we don’t need to provide value for this argument in action, but we can set different value using setter(generated automatically).</p><p>In the destination fragment we are use another self generated class, to help deserialize incoming data- this class name is the destination fragments name with ‘Args’ appended to the end.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9ddae08e265b627dd792dedf0b0a167/href">https://medium.com/media/d9ddae08e265b627dd792dedf0b0a167/href</a></iframe><p><em>Notice, if you try to retrieve arguments in destination fragment using TopicDetailFragmentArgs.fromBundle() without adding the arguments in type-safe way in your origin fragment, you will receive IllegalArgumentException at runtime.</em></p><p><strong>Deep linking<br></strong>Navigation component helps navigate user to specific destination inside the app from deep link, and handling the proper back navigation, just as though user entered the app from the app’s entry point.</p><p>To create a deep linking destination inside navigation editor, select the desired destination fragment and click + in the ‘Deep links’ section in the attribute panel. Enter the desired URI link, URIs without a scheme are assumed as http and https. You can add parameters inside your URI with {parameter_name} and retrieve the value from the ‘Bundle’ in your destination fragment. Let’s say we created URI ‘www.example.com/topics/{id}’. Notice that in the navigation editor xml a new element has been created inside for the desired destination</p><pre>&lt;deepLink app:uri=&quot;www.example.com/topics/{id}&quot;/&gt;</pre><p>To handle the deep linking we need to add intent filter to our AndroidManifest.xml. In Android Studio 3.2 we can only add our navigation graph xml inside our activity element, and Android Studio will automatically generate the proper intent filters at build time</p><pre>&lt;nav-graph android:value=&quot;@navigation/nav_graph&quot; /&gt;</pre><p>Inside our destination fragment we can retrieve the ‘id’ value by just calling</p><pre>val id=<em>arguments</em>?.getString(&quot;id&quot;)</pre><blockquote>Notice that clicking back/up button from fragment that was accessed from a deep link, will take you to the start destination inside your navigation graph. If you want to create more complex back navigation from deep link destination, you need to use nested navigation graphs, each with its own start destination.</blockquote><p><strong>Transition between destinations<br></strong>You can easily add transition between your destinations. Select the desired navigation action between destinations and select the desired transition in attribute panel, you can add ‘Enter’, ‘Exit’, ‘Pop Enter’ and ‘Pop Exit’ transition. You can create custom animation transitions and select them from the attribute panel. The selected transition will be added to ‘Action’ element, inside the destination in navigation graph xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da9bb8525fd5ec81e6b38422060e724b/href">https://medium.com/media/da9bb8525fd5ec81e6b38422060e724b/href</a></iframe><p><strong>Global actions<br></strong>Sometimes we’ll want to access the same destination from different origins. Instead of creating multiple actions from different origins to the same destination, you can create one global action to desired destination.</p><p>To create global actions, select the desired destination in navigation graph. Right click and in the menu select ‘Add action’ and click on ‘Global’, this will create a global action inside your navigation graph root element</p><pre>&lt;action android:id=&quot;@+id/action_global_signInFragment&quot; app:destination=&quot;@id/signInFragment&quot;/&gt;</pre><p>To use global action you need to have an id for your navigation graph (currently it is not generated automatically).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12c08837829853cd5b4d36aed7625be9/href">https://medium.com/media/12c08837829853cd5b4d36aed7625be9/href</a></iframe><p>Now you can use global actions by calling navigation() method and passing it the id of the desired global action.</p><pre>NavHostFragment.findNavController(this@CreateTopicFragment).navigate(R.id.<em>action_global_signInFragment</em>)</pre><p>To go back to your origin fragment , just call popBackStack() method with global action id.</p><pre>NavHostFragment.findNavController(this@SignInFragment).popBackStack(R.id.<em>action_global_signInFragment</em>, true)</pre><p><strong>Conditional navigation<br></strong>Sometimes your destination should be accessed only if some condition exists. For example, if the user wants to create a new topic but is not logged in- you need to navigate him to the sign-in screen. This can be done by checking if the user is logged in inside your destination fragment. If he is not logged in, navigate him to sign-in destination, and after the sign-in process he will be returned to the ‘create topic’ screen. Currently there is a bug in navigation library alpha1, that causes exception when navigating from lifecycle callbacks(onCreate, onResume etc.), to avoid this exception you can use delayed navigation</p><pre><em>launch</em>(<em>UI</em>) <strong>{<br></strong><em>delay</em>(1L)<br>NavHostFragment.findNavController(this@CreateTopicFragment).navigate(R.id.<em>action_global_signInFragment</em>) <strong>}</strong></pre><p><strong>Final words<br></strong>Currently, the library is in early alpha stage, and you may and will encounter some bugs. But this shouldn’t stop you from experimenting with this library. And if you stumble upon any bugs, you should fill them in google issue tracker, this will help fix them and make the library better</p><p><a href="https://issuetracker.google.com/issues/new?component=409828&amp;template=1093757">https://issuetracker.google.com/issues/new?component=409828&amp;template=1093757</a></p><p>You can read more about this new component on official android documentation</p><p><a href="https://developer.android.com/topic/libraries/architecture/navigation/">https://developer.android.com/topic/libraries/architecture/navigation/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b5a7aab8aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>