android-architecture-navigation

How I can retrieve current fragment in NavHostFragment?

旧时模样 提交于 2019-11-27 23:50:55
问题 I tried to find a method in the new Navigation components but I didn't find anything about that. I have the current destination with : mainHostFragment.findNavController().currentDestination But I can't get any reference to the displayed fragment. 回答1: Navigation does not provide any mechanism for getting the implementation (i.e., the Fragment itself) of the current destination. As per the Creating event callbacks to the activity, you should either communicate with your Fragment by Having the

How to clear navigation Stack after navigating to another fragment in Android

末鹿安然 提交于 2019-11-27 11:33:05
I am using The new Navigation Architecture Component in android and I am stuck in clearing the navigation stack after moving to a new fragment. Example: I am in the loginFragment and I want this fragment to be cleared from the stack when I navigate to the home fragment so that the user will not be returned back to the loginFragment when he presses the back button. I am using a simple NavHostFragment.findNavController(Fragment).navigate(R.id.homeFragment) to navigate. Current Code : mAuth.signInWithCredential(credential) .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>()

Navigation Architecture Component - Login screen

冷暖自知 提交于 2019-11-27 02:56:21
问题 I am planning to implement navigation like this: The problem I face is when user is in LoginFragmennt and presses back button it again loads up LognFragment ie. stuck in loop. I navigate to LoginnFragment using conditional navigation as per this answer. How to properly implement this? 回答1: One of the solutions that i can propose is to override inside your activity onBackPressed method, and finish the activity if your current destination(before on back pressed handled) is login fragment.

Navigation Component, Control when to show hamburger or back icon

 ̄綄美尐妖づ 提交于 2019-11-27 01:20:39
问题 I have the following Activity class MainActivity : AppCompatActivity() { private lateinit var drawerLayout: androidx.drawerlayout.widget.DrawerLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.main_activity) drawerLayout = drawer_layout val navController = Navigation.findNavController(this, R.id.fragment_main_navHost) setSupportActionBar(toolbar) NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)

Fragments destroyed / recreated with Jetpack's Android Navigation components

蹲街弑〆低调 提交于 2019-11-27 00:55:29
问题 I'm trying to implement Navigation with Jetpack's architecture components in my existing app. I have a single activity app where the main fragment ( ListFragment ) is a list of items. Currently, when the user taps on a list item a second fragment is added to the stack by fragmentTransaction.add(R.id.main, detailFragment) . So when back is pressed the DetailFragment is detached and the ListFragment is shown again. With Navigation architecture this is handled automatically. Instead of adding

How to clear navigation Stack after navigating to another fragment in Android

旧城冷巷雨未停 提交于 2019-11-26 12:23:34
问题 I am using The new Navigation Architecture Component in android and I am stuck in clearing the navigation stack after moving to a new fragment. Example: I am in the loginFragment and I want this fragment to be cleared from the stack when I navigate to the home fragment so that the user will not be returned back to the loginFragment when he presses the back button. I am using a simple NavHostFragment.findNavController(Fragment).navigate(R.id.homeFragment) to navigate. Current Code : mAuth