<?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 Azure Li on Medium]]></title>
        <description><![CDATA[Stories by Azure Li on Medium]]></description>
        <link>https://medium.com/@azureli?source=rss-789e8a85126a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*a23uiXzXPG-j-PPJ.</url>
            <title>Stories by Azure Li on Medium</title>
            <link>https://medium.com/@azureli?source=rss-789e8a85126a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:13:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@azureli/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[Back navigation in Fragment]]></title>
            <link>https://medium.com/@azureli/back-navigation-in-fragment-134c0fc5ba9e?source=rss-789e8a85126a------2</link>
            <guid isPermaLink="false">https://medium.com/p/134c0fc5ba9e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[fragments]]></category>
            <dc:creator><![CDATA[Azure Li]]></dc:creator>
            <pubDate>Tue, 07 Apr 2020 00:09:04 GMT</pubDate>
            <atom:updated>2020-04-07T00:09:04.691Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Use Case</strong>: There is a Activity and which includes few Fragments , One day if you want to mange few pages information in one Fragment , and you need to control the navigation inside bothFragment and and Activity .</p><p>Android provide a <strong><em>onBackPressedDispatcher </em></strong><em>to implement custom back navigation:</em></p><p><a href="https://developer.android.com/guide/navigation/navigation-custom-back#kotlin">Provide custom back navigation | Android Developers</a></p><pre>class MyActivity : AppCompatActivity() {<br><br>    override fun onBackPressed() {<br>        <em>if </em>(getOnBackPressedDispatcher().hasEnabledCallbacks()) {<em>         <br>            super</em>.onBackPressed();   // dispatch event to custom callback, which implemented in fragment</pre><pre>       } <em>else </em>{<br>       // use activity backPressed if there is no callback          added to <strong>mOnBackPressedDispatcher</strong></pre><pre>       }<br>    }<br>    ...<br>}</pre><pre>class MyFragment : Fragment() {</pre><pre><em>    private val </em>callback = <em>object </em>: OnBackPressedCallback(<em>true</em>) {<br>        <em>override fun </em>handleOnBackPressed() {<br>            // handle back button event in fragment<br>        }<br>    }</pre><pre><em>    override fun </em>onResume() {<br>        <em>super</em>.onResume()<br>        // add callback when fragment selected or visible</pre><pre>        requireActivity()<br>            .onBackPressedDispatcher<br>            .addCallback(this, callback) <br>    }</pre><pre>    fun goToNextFragment() {<br>         callback.remove() // remove callback in case other fragments has callback as well <br>    }<br>    ...<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=134c0fc5ba9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>