Navigation Component - Android Studio Tutorial

Stevdza-San · 189K views · 2020 · 12:11

Open on YouTube

Software (other)Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when pointing Android developers to the Navigation component for moving between fragments in a single-activity app.

Recommended by 2 people across 2 different months, 2021 to 2023.

What it is

A 12-minute beginner tutorial from Stevdza-San on Android Jetpack's Navigation component in Android Studio. It explains the navigation graph, NavHost and NavController and shows how to move between fragment destinations.

What people said

Recommends Ömer Seyfettin Yavuzyiğit · 2022-04 · Stack Overflow · on “Single Activity login flow Android”

1.way val homeFragment = HomeFragment() val listFragment = ListFragment() val profileFragment = ProfileFragment() nav_view.setOnItemSelectedListener { when (it) { R.id.homeFragment -> setCurrentFragment(homeFragment) R.id.listFragment -> setCurrentFragment(listFragment) R.id.profileFragment -> setCurrentFragment(profileFragment) } return@setOnItemSelectedListener } private fun setCurrentFragment(fragment: Fragment) = supportFragmentManager.beginTransaction().apply { replace(R.id.nav_host_fragment_activity_main, fragment) addToBackStack(null) //If you delete this, press the back button, it will not return to the previous fragment. commit() } 2.way Navigation with [this video]

Recommends Mert · 2022-10 · Stack Overflow · on “Toolbar missing in the child activity”

Sure, i suggest you to use single activity and as many as fragment you want. This Philipp guy is a good teacher and in this video for the beginners link [LINK] For the navigation between fragments, the best approach is to use navigation components and this video from Stevdza-San teaching that link [this video]

Cites amimic11 · 2021-03 · Stack Overflow · on “Trying to send bundle argument”

you can use jetpack library for android called Navigation graph, that handles such issues like passing data between fragments and similar stuff, along with other features u can search Initially you need to create a navigation graph, that contains all the fragment with connected graph as per your application logic. For passing data between fragment, you need to create a argument in navigation action and from there you can send/receive your data easily, for more information and detail steps refer the links. Navigation graph : [this video] Navigation safe args : [LINK]

Cites Eray Erdin · 2023-11 · Stack Overflow · on “Using Fragment inside Navigation Fragment”

Codes Main Activity // MainActivity.kt class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } } <!-- activity_main.xml --> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android=" [LINK] " xmlns:app=" [LINK] " xmlns:tools=" [LINK] " android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <androidx.fragment.app.FragmentContainerView android:id="@+id/fragmentContainerView" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost