This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FragmentA : BundleFragment() { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |