android-architecture-navigation

Add (not replace) Fragment with Navigation Architecture Component

拟墨画扇 提交于 2019-12-03 04:46:27
问题 I have an activity with a product list fragment and many other fragments and i am trying to use Architecture component navigation controller. The problem is: it replaces the (start destination)product list fragment and I don't want the list to be reloaded when user click back button. How to make the fragment transaction as add not replace. 回答1: I faced the same problem, while waiting on add and other options for fragment transactions I implemented this work around to preserve the state when

Add (not replace) Fragment with Navigation Architecture Component

£可爱£侵袭症+ 提交于 2019-12-02 18:02:47
I have an activity with a product list fragment and many other fragments and i am trying to use Architecture component navigation controller. The problem is: it replaces the (start destination)product list fragment and I don't want the list to be reloaded when user click back button. How to make the fragment transaction as add not replace. I faced the same problem, while waiting on add and other options for fragment transactions I implemented this work around to preserve the state when hitting back. I just added a check if the binding is present then I just restore the previous state, the same

How to keep fragment view state?

随声附和 提交于 2019-12-02 16:19:17
问题 I have doubt in fragment system. I have two fragments like A and B If i move A to B , Navigation.findNavController(v).navigate(R.id.B) Now A fragment onDestroyView is called i know it's normal. After in B Fragment i called PopBackStack Navigation.findNavController(v).popBackStack() now A fragment onViewCreated is called i also know it's normal. Now A fragment all ui is initial state. My question is how to keep A fragment UI State like recyclerview scroll position, FAB button visibility, etc

Android Navigation Component Not Displaying Fragment

不想你离开。 提交于 2019-12-02 02:12:09
I'm trying to implement the new Android Navigation Component in an existing app. I have 2 fragments that are identical except for their name. When I set the startDestination to fragment2, the fragment seems to be shown correctly. When the startDestination is set to fragment1, I don't see the inflated view but I do see the "Fragment 1 created" toast. What am I doing incorrectly? class Fragment1 : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { Toast.makeText(context, "Fragment 1 created", Toast.LENGTH_LONG).show()

How to prevent previous fragment to show up after pressing back button using navigation controller?

我的梦境 提交于 2019-12-01 22:33:23
I am trying to use the navigation controller right now. I want to move from LoginFragment to HomeFragment . In LoginFragment I use this code below to move to HomeFragment . Navigation.findNavController(view).navigate(homeDestination) However, when I tap the back button in the HomeFragment , it will go back to LoginFragment , I expect that when I tap the button it will close the app. In old way, if I use activity instead of using Fragment , I usually do something like this to get that expected behaviour: val intent = Intent(this,HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY

Pass data/bundle using navigateUp in Android Navigation Component

好久不见. 提交于 2019-12-01 21:58:58
I found the question but does not have solution in code I want to have data when backpress/manual back happens. I am using navigateUp() to go back. How can I pass data to previous fragment? navigateUp() does not have any facility to pass data to previous fragment. Even I did not find solution using Safe Args . It's passing data forward. I want to have in backward Frad B -> Frag A. My code to go back to previous fragment Navigation.findNavController(view).navigateUp() My question is, How can i get data in previous fragment. I can navigate to Frag A from Frag B using Natig Babayev According to

Why does android.arch.navigation cause Program type already present: android.support.v4.os.ResultReceiver$1?

↘锁芯ラ 提交于 2019-12-01 05:43:22
I am using Android Studio version Android Studio 3.2 Canary 14 Build #AI-181.4668.68.32.4763614, built on May 4, 2018 JRE: 1.8.0_152-release-1136-b02 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.11.6 While investigating the new Architectural navigation components android.arch.navigation I have encountered this build failure. AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$1","sources":[{}],"tool":"D8"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE: Build failed with an exception. * What went

How to implement shared transition element form RcyclerView's item to Fragment with Android Navigation Component?

假如想象 提交于 2019-12-01 05:26:56
I have a pretty straightforward case. I want to implement shared element transition between item in RececlerView and fragment . I'm using android navigation component in my app. There is an article about shared transition on developer.android and topic on stackoverflow but this solution works only for view that located in fragment layout that starts transition and doesn't work for items from RecyclerView . Also there is a lib on github but i don't want to rely on 3rd party libs and do it by myself. Is there some solution for this? Maybe it should work and this is just a bug? But I haven't

Why does android.arch.navigation cause Program type already present: android.support.v4.os.ResultReceiver$1?

早过忘川 提交于 2019-12-01 03:58:36
问题 I am using Android Studio version Android Studio 3.2 Canary 14 Build #AI-181.4668.68.32.4763614, built on May 4, 2018 JRE: 1.8.0_152-release-1136-b02 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.11.6 While investigating the new Architectural navigation components android.arch.navigation I have encountered this build failure. AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$1","sources":[{}],"tool":"D8"} :app

How I can retrieve current fragment in NavHostFragment?

只愿长相守 提交于 2019-11-30 18:33:24
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. 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 Fragment register a callback in its onAttach method, casting your Activity to an instance of an interface