android-architecture-navigation

how to implement Conditional Navigation in navigation architecture components

戏子无情 提交于 2019-12-04 20:09:07
问题 In the new Navigation architecture component, how to implement conditional navigation? Currently I have a single activity with LoginFragment and HomeFragment. Based on a certain login_flag, I used to call either fragment from the MainActivity. Since LoginFragment is called only once, I have set the startDestination to HomeFragment and the Navigation loads this HomeFragment. is there any way to check the login_flag before the Navigation loads the HomeFragment. 回答1: You can add navigation

NavHostFragment not accessible from XML

时光总嘲笑我的痴心妄想 提交于 2019-12-04 05:24:11
I wanted to try new Navigation library. After following this guideline I experienced error at runtime: Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists, is public, and has an empty constructor that is public in resource file activity_home.xml . This file is very

Proguard causing runtime exception with Android Navigation Component

南笙酒味 提交于 2019-12-04 04:41:32
I'm experiencing this crash when using proguard after integrating the NavigationComponent ( android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01 ) into my project with target and compile sdk of 27 2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mypackage.myapp.x, PID: 24573 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp.x/com.mypackage.myapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment at android.app

How to set target fragment of a dialog when using navigation components

∥☆過路亽.° 提交于 2019-12-04 03:07:32
I'm showing a dialog inside a fragment using childFragmentManager or within an Activity using the supportFragmentManager , in the process I would like to set the target fragment, like this: val textSearchDialog = TextSearchDialogFragment.newInstance() textSearchDialog.setTargetFragment(PlaceSearchFragment@this, 0) But when running that code I get the error: java.lang.IllegalStateException: Fragment TextSearchDialogFragment{b7fce67 #0 0} declared target fragment PlaceSearchFragment{f87414 #0 id=0x7f080078} that does not belong to this FragmentManager! I don't know how to access the

IllegalStateException: Link does not have a NavController set

拈花ヽ惹草 提交于 2019-12-04 02:59:50
问题 I'm using Android Navigation Component for Navigation. I have a LoginFragment which has a button to transition to SignUpFragment. On clicking the button I'm getting this error. java.lang.IllegalStateException: View android.support.v7.widget.AppCompatButton{49d9bd1 VFED..C.. ...P.... 201,917-782,1061 #7f090172 app:id/signUpLink} does not have a NavController set Here is my nav_graph.xml <navigation xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com

Android Jetpack Navigation library and onActivityResult

纵然是瞬间 提交于 2019-12-04 02:53:48
I'm trying to migrate an app to the new Navigation Architecture Component that was announced at GoogleIO'18 Suppose I need to use an activity that is normally started with startActivityForResult . This activity comes either from a library or a system activity, so I can't modify it. Is there any way to include this activity as a destination in the navigation graph and get results from it? The only solution I have so far is to wrap that activity behind a fragment that catches the result and then presents it to the navigation graph: class ScannerWrapperFragment : Fragment() { private val

How do I link multiple activities in android navigation editor?

随声附和 提交于 2019-12-04 01:12:32
I'm learning android development and the navigation component, trying to link multiple activities as the document had written. But it seems like it's impossible to create action between two activities to a single navigation graph which was reasonable to me as the document had written. The NavController and its navigation graph is contained within a single activity. Therefore, when migrating an existing project to use the Navigation Architecture Component, focus on migrating one Activity at a time by creating a navigation graph for the destinations within each Activity. So the question is what

how to implement Conditional Navigation in navigation architecture components

微笑、不失礼 提交于 2019-12-03 12:42:56
In the new Navigation architecture component, how to implement conditional navigation? Currently I have a single activity with LoginFragment and HomeFragment. Based on a certain login_flag, I used to call either fragment from the MainActivity. Since LoginFragment is called only once, I have set the startDestination to HomeFragment and the Navigation loads this HomeFragment. is there any way to check the login_flag before the Navigation loads the HomeFragment. You can add navigation listener inside your activity, and from there navigate to LoginFragment based on your conditions, like this:

How to get a result from fragment using Navigation Architecture Component?

只愿长相守 提交于 2019-12-03 06:46:09
问题 Let's say that we have two fragments: MainFragment and SelectionFragment . The second one is build for selecting some object, e.g. an integer. There are different approaches in receiving result from this second fragment like callbacks, buses etc. Now, if we decide to use Navigation Architecture Component in order to navigate to second fragment we can use this code: NavHostFragment.findNavController(this).navigate(R.id.action_selection, bundle) where bundle is an instance of Bundle (of course)

Could not find androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01

笑着哭i 提交于 2019-12-03 05:08:05
I want to use Navigation Architecture Components. But I got a problem with importing safeargs Sync message: Could not find androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01. Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0.0-alpha01.pom https://dl.google.com/dl/android/maven2/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0.0-alpha01.jar https://jcenter.bintray.com/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args