Skip to content

Instantly share code, notes, and snippets.

Avatar

Mahdi Nouri PHELAT

View GitHub Profile
@PHELAT
PHELAT / MainActivity.kt
Created May 11, 2019
navigateUp with Bundle!
View MainActivity.kt
class MainActivity : FragmentResultActivity() {
// You can use updateNavHostFragmentId function to update
// nav host fragment's id at runtime.
override fun getNavHostFragmentId(): Int = R.id.nav_host_fragment
}
@PHELAT
PHELAT / FragmentB.kt
Last active May 11, 2019
navigateUp with Bundle!
View FragmentB.kt
// This is an extension function on Fragment
import com.phelat.navigationresult.navigateUp
class FragmentB : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
anotherButton.setOnClickListener {
val bundle = Bundle().apply {
putBoolean(IS_LOG_IN_SUCCESSFUL, true)
}
@PHELAT
PHELAT / FragmentA.kt
Last active May 11, 2019
navigateUp with Bundle!
View FragmentA.kt
class FragmentA : BundleFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
myButton.setOnClickListener {
navigate(FragmentADirections.fragmentAToFragmentB(), REQUEST_CODE)
// If you aren't using SafeArgs plugin, you can navigate with direction id
navigate(R.id.fragmentAToFragmentB, REQUEST_CODE)
}
}
override fun onFragmentResult(requestCode: Int, bundle: Bundle) {
@PHELAT
PHELAT / FragmentA.kt
Last active May 10, 2019
navigateUp with Bundle!
View FragmentA.kt
class FragmentA : BundleFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
myButton.setOnClickListener {
navigate(FragmentADirections.fragmentAToFragmentB(), REQUEST_CODE)
// If you aren't using SafeArgs plugin, you can navigate with direction id
navigate(R.id.fragmentAToFragmentB, REQUEST_CODE)
}
}
companion object {
@PHELAT
PHELAT / FragmentA.kt
Last active May 10, 2019
navigateUp with Bundle!
View FragmentA.kt
class FragmentA : BundleFragment() {
...
}
You can’t perform that action at this time.