android-jetpack-navigation

Android Espresso does not have a NavController set Error

我是研究僧i 提交于 2020-07-23 06:51:19
问题 I am trying to test a fragment in my navigation architecture and my test is as follows: test.kt @RunWith(AndroidJUnit4::class) @MediumTest internal class AddingAccountTest{ @get:Rule var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) @Before fun loadCorrespondingFragment(){ } @Test fun checkThatAllFieldsInFormAreEmpty(){ // Create a TestNavHostController val navController = TestNavHostController(ApplicationProvider.getApplicationContext())

Android navigation components with deep link: onNewIntent called multiple times

荒凉一梦 提交于 2020-07-22 08:29:44
问题 This time I need your help regarding the use of android navigation components with deeplink. I have been following this documentation and the connection between fragment and deeplink is working fine. The problem comes in regards to the activity that is receiving the deeplink. In my case, I set the android:launchMode="singleTask" <activity android:name=".features.welcome.WelcomeActivity" android:launchMode="singleTask"> <nav-graph android:value="@navigation/welcome_nav_graph" /> </activity>

androidx.navigation.fragment.NavHostFragment is not accessible from xml file

人走茶凉 提交于 2020-07-09 13:28:47
问题 I am trying to use androidx navigation with bottom navigation view.So when i put fragment with android:name = "androidx.navigation.fragment.NavHostFragment" in xml file it gives me an error. I guess that xml doesn't see this library or this Fragment Here is xml file : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout

How to pass data between fragments when using bottomNavView

落花浮王杯 提交于 2020-06-26 14:15:36
问题 I have an app with one activity and two fragments, And I navigate using jetpack navigation. In my "Main" fragment, I've a button that trigger function inside the viewModel: edit_text_button.setOnClickListener { homeViewModel.onButtonClicked() } onButtonClicked inside viewModel , basically shuffle the list and trigger observer in main fragment. fun onButtonClicked() { initList = (1..9).shuffled() _list.value = initList } My question is: How can I pass every time the updated list to the second

How to pass data between fragments when using bottomNavView

三世轮回 提交于 2020-06-26 14:14:29
问题 I have an app with one activity and two fragments, And I navigate using jetpack navigation. In my "Main" fragment, I've a button that trigger function inside the viewModel: edit_text_button.setOnClickListener { homeViewModel.onButtonClicked() } onButtonClicked inside viewModel , basically shuffle the list and trigger observer in main fragment. fun onButtonClicked() { initList = (1..9).shuffled() _list.value = initList } My question is: How can I pass every time the updated list to the second

Android Navigation Component + Login Flow + Nested BottomNavigationView

流过昼夜 提交于 2020-05-25 04:49:04
问题 I'm struggle building a Navigation, like on the image below, with the Android Navigation Component. I need a "Login Flow", check if the user is logged in and then navigate to the main part of the app (also clearing the backstack). The main part contains a BottomNavigationView with three tabs. But if I click on a settings icon on the toolbar, I also want to display a fullscreen SettingsFragment. Did I need two NavHostFragments with separate navigation graphs? If yes, how can I combine them and

Deeplink isn't correctly redirect if the app is already opened

自作多情 提交于 2020-05-17 06:12:05
问题 I'm using Jetpack Navigation for deeplinks. I've added android:launchMode="singleTask" to my Activity. Deeplink is redirected correctly if the app wasn't opened before. However, if the app exists in memory, the app is coming to the foreground but deeplink isn't opened correctly. My device is Pixel 2 with Android 10. I see that onCreate is called only the first time I'm opening app. However, onNewIntent is called every time I'm clicking deeplink. Is it a bug in Jetpack Navigation or I forgot

How to switch to other fragment in different back stack using Navigation Component?

陌路散爱 提交于 2020-05-12 13:57:09
问题 I have 3 bottom navigation tabs called Home, Dashboard, Profile . In Home , I have Fragment1 and Fragment2 , In Dashboard , I have Fragment3 and Fragment4 And in Profile , I have MyProfile and EditProfile . Now, in Fragment2 , a button changeAvatar can open EditProfile in stack Profile . Because EditProfile should be in tab Profile , so if I don't want to include EditProfile into navGraph of Home , how can I achieve that behavior? 回答1: try with the deep link Navigation graph. <navigation ...>

How to switch to other fragment in different back stack using Navigation Component?

╄→尐↘猪︶ㄣ 提交于 2020-05-12 13:56:28
问题 I have 3 bottom navigation tabs called Home, Dashboard, Profile . In Home , I have Fragment1 and Fragment2 , In Dashboard , I have Fragment3 and Fragment4 And in Profile , I have MyProfile and EditProfile . Now, in Fragment2 , a button changeAvatar can open EditProfile in stack Profile . Because EditProfile should be in tab Profile , so if I don't want to include EditProfile into navGraph of Home , how can I achieve that behavior? 回答1: try with the deep link Navigation graph. <navigation ...>

can I send nullable data type as argument using safeargs ? if not what should I do?

南楼画角 提交于 2020-04-30 06:26:25
问题 say I have 2 fragments. Login and Home. I set Home fragment as a global destination that has userData as arguments if the user is not logged in yet, then it will start from login fragment. after login and get userData from server then it will navigate to Home and pass userData using this code val home = AuthenticationFragmentDirections.actionGlobalHomeFragment(userData) Navigation.findNavController(view).navigate(home, navOptions) but the problem is when the user already login and open the