Junior
What navigation methods in Android do you know?
sobes.tech AI
Answer from AI
There are several main navigation methods in Android:
- Up (Go up one level): Usually implemented with a back arrow button in the ActionBar/Toolbar. It takes the user to the previous screen in the app's logical hierarchy.
- Back: Implemented with the system "Back" button. It returns the user to the previous screen they visited.
- Home: Returns to the main screen of the app or device.
- Deep Links: Direct navigation to a specific screen or resource within the app via a link. They can be created from external sources (web, other apps) or within the app itself.
- Navigation Drawer: A side sliding panel containing links to various sections of the app.
- Bottom Navigation Bar: A bar at the bottom of the screen allowing quick switching between main sections of the app.
Main approaches to implementing navigation:
- Using
startActivityForResultandonActivityResult: An outdated method of passing data between Activities. - Passing data via Intent Extras: A simple way to pass primitive data and serializable/parcellable objects between Activities.
FragmentTransaction: Managing fragments (adding, replacing, removing, etc.) for navigation within an Activity.- Navigation Component: An official library from Google that simplifies navigation between different app components (Activity, Fragment, Custom Views). It provides a visual navigation graph editor, argument passing, and back stack management.
// Example of navigation with Navigation Component
findNavController().navigate(R.id.action_currentFragment_to_nextFragment)
// Passing arguments with Navigation Component
val bundle = Bundle()
bundle.putString("key", "value")
findNavController().navigate(R.id.action_currentFragment_to_nextFragment, bundle)