android / codelab-android-navigation Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
The directions are to:
- Remove code added in step 6, if it's still there.
I believe that they should be to
Remove code added in step 5, ...
I click on bottomNavigationView From DeeplinkFragment to HomeFragment, Discovery will recreate HomeFragment.
Why ? It is a feature or bug ?
2019-01-31 18:08:31.500 29778-29778/com.example.android.codelabs.navigation D/Test: onCreate
2019-01-31 18:08:34.453 29778-29778/com.example.android.codelabs.navigation D/Test: onCreate
It appears as though you have a navigation drawer in the layout but don't actually use it. I've cloned, built, and installed and the drawer is not functional. I'm curious how the new navigation component works with https://developer.android.com/reference/android/support/design/widget/NavigationView.OnNavigationItemSelectedListener
It might be clearer if the instructions just said "Go to the Google app and enter 'www.example.com/blah'. If you followed the instructions, you'll see a disambiguation dialog". I don't use the Google app so I was puzzled where to test out the code for step 11. It took me a while to figure out where the search bar is
My editor complains that element nav-graph
is not allowed here for this line of code
https://github.com/googlecodelabs/android-navigation/blob/master/app/src/main/AndroidManifest.xml#L42
and after following the steps suggested in the codelabs tutorial here https://codelabs.developers.google.com/codelabs/android-navigation/#10, in the very last step - this doesn't happen
Opening www.example.com/hello/ triggers the intent chooser
I just see a search result on google.com. In my case I launched it in a Genymotion VM which only had one browser -- which I assume would mean there was nothing to resolve for the intent chooser (which in the example shows Chrome and WebView Browser Tester)
Does the nav-graph
element need to go somewhere else?
Editor
Android Studio 3.3 Canary 10
Build #AI-182.4129.33.33.4996246, built on September 6, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Player VM
Nexus 6X API 23
Excellent codelab, essentially "living documentation" for the AAC "Navigation" component.
One way to make it even more useful would be to create a branch containing the final
state of the project (reflecting state when the codelab is completed)
The deep linking by way of Chrome browser, by accessing url: www.example.com/hello does not work, on either the simulator, or on physical device.
at the bottom of the page
val button = view.findViewById<Button>(R.id.navigate_destination_button)
button?.setOnClickListener(
Navigation.createNavigateOnClickListener(R.id.flow_step_one_dest, null)
)
calling createNavigateOnClickListener in onClickListener isn't equal to previous example with
val button = view.findViewById<Button>(R.id.navigate_destination_button)
button?.setOnClickListener(
findNavController().navigate(R.id.flow_step_one_dest)
)
should be like
Navigation.createNavigateOnClickListener(R.id.flow_step_one_dest, null)
another point is that setOnClickListener
should be with curly braces { }
Sample code shown is:
<deepLink app:uri="www.example.com/{myarg}"/>
That's the deep link from the previous step. In this step, it should be:
<deepLink app:uri="www.iana.org/domains/{myarg}"/>
Instructions should then be to navigate to www.example.com and click the link. Upon choosing the app from the sharing list, you then see 'reserved' displayed in the fragment.
onNavDesintationSelected instead of onNavDestinationSelected
here: https://codelabs.developers.google.com/codelabs/android-navigation/index.html?index=..%2F..%2Findex#8
When go to Settings Fragment, PopUp menu stay visible and if I click again Settings Fragment is Overlapped
as stated on another ticket here: "...You also just will see the drawer when e.g. entering split screen mode or rotate to landscape."
can you please clarify how we can show the drawer menu when in portrait mode ? i think it would be great if this can be added to the tutorial (which is fantastic).
In old intent-filter way, we could setup different URI hosts through manifestPlaceholders
for each product flavor easily, e.g. alpha/beta/production URI host. How to migrate into Navigation <deepLink app:uri="{host}"/>
way?
How can I use navigation in the project which build whit androix
Having crash issues in navigation while frequently changing the fragments in and out. in android-sunflower applciation
how can i get mBackStack info to know stack has contain some page,I want implement a function like Activity cleanTop , such as page A->B->A,I hope backStack remove B and make A to top,but now it will create a new page A。
If I try to add a new fragment/actions(for ex.) in the text tab rather than adding it from the design tab; once I add it to the action tab, the changes are not reflected on the design tab. Moreover there is no refresh option that I could see to refresh the design tab.
It would be great, if the design tab could refresh real time based on the metadata added in the text tab.
why the project is built upon android studio 3.2 preview version
it would be better if build with normal android studio so anyone can use it
I am getting these errors when trying to build the project
Failed to resolve: appcompat-v7
Open File
Failed to resolve: cardview-v7
Open File
Failed to resolve: animated-vector-drawable
Open File
Failed to resolve: support-vector-drawable
Open File
Failed to resolve: support-v4
Open File
Failed to resolve: support-fragment
Open File
Failed to resolve: support-core-ui
Open File
Failed to resolve: runtime
Open File
Failed to resolve: livedata-core
Open File
Failed to resolve: common
Open File
Failed to resolve: support-annotations
Open File
Failed to resolve: viewmodel
Open File
In the tutorial is never mentioned that you have to add the
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07'
in the /build.gradle
file
On Step 8, the code
val safeArgs = FlowStepFragmentArgs.fromBundle(arguments)
produces a type mismatch error: inferred type is Bundle? but Bundle was expected
After forcing the default navigation_activity.xml to be loaded on app launch (i.e.
use nav drawer), it is observed that while the nav drawer may be opened by swiping
in from the left screen edge, the hamburger icon is completely inoperable i.e. it
does nothing when pressed -- correct behavior would be to open the nav drawer.
我是否可以在fragment中嵌套使用bottomnavigationview+4个fragment选项卡呢,我写了个demo,发现在activity中嵌套可以实现。但是在fragment中嵌套使用无法实现联动
when adding the navigation options the code in the TODO is this:
val options = NavOptions.Builder()
.setEnterAnim(R.anim.slide_in_right)
.setExitAnim(R.anim.slide_out_left)
.setPopEnterAnim(R.anim.slide_in_left)
.setPopExitAnim(R.anim.slide_out_right)
.build()
view.findViewById<Button>(R.id.navigate_dest_bt)?.setOnClickListener {
findNavController(it).navigate(R.id.flow_step_one, null, options)
}
This is not compiling because it is the findNavController is expecting a fragment but is getting a 'View' as an input
it should be the keyword 'this' to pass the current fragment and the transition
I create a splash fragment, I hope when I go to home fragment, the splash fragment is removed, what should I do?
app:type="integer"
change to
type="integer"
How to navigate activity.....
Step 10 "Deep Linking to a destination" contains the following screen shot at the end of the page. Notice the Up button on the upper-left corner.
I can't speak for others, but the Up button never showed up for my case, even when I reach the screen from the widget in the home screen. The only way to make it show is to remove R.id.deeplink_dest
in MainActivity.kt
.
class MainActivity : AppCompatActivity() {
...
// TODO STEP 9.5 - Create an AppBarConfiguration with the correct top-level destinations
// You should also remove the old appBarConfiguration setup above
val drawerLayout : DrawerLayout? = findViewById(R.id.drawer_layout)
appBarConfiguration = AppBarConfiguration(
setOf(R.id.home_dest, R.id.deeplink_dest), // <-- Remove "R.id.deeplink_dest".
drawerLayout)
But if I do, the Up button always shows up in "Deep Link" screen, even when I reach the screen from Navigation Drawer or Bottom Navigation.
Is the Up button supposed to show up only when I reach it from the "Deep Link" widget? If so, how do I make it show up, but not show up when reaching it from Navigation Drawer or Bottom Navigation?
A Fragment has a ViewPager with multiple fragments how to achieve jump
There is no navigateUp() fun with AppBarConfiguration param:
https://developer.android.com/reference/androidx/navigation/NavController.html#navigateUp()
When in portrait mode (so the navigation drawer is not visible, but the bottom bar is) the up button in the toolbar is shown when switching to the deep link tab via the bottom bar. As far as I know this shouldn't be the case. I would only have it visible when you're in landscape mode and the drawer is active.
I understand that this is done by the Navigation Components handling switching the tab as a simple forward navigation. However that isn't the case - as all tabs are created equal. ;)
So might be that's not a bug in the codelab, but in the Navigation Components library? Then again, it would also have to accomodate for what happens when you then switch to landscape where the up button would suddenly become appropriate - this doesn't sound trivial.
I don't understand the reason why the NavigationUI doesn't admit a override on the onNavDestinationSelected or just a main bundle for all the view Like this:
setupWithNavController(mBinding.navigation, mNavController, mArguments.toBundle())
onNavDestinationSelected(item, navController, false, args)
And all fragments that are implemented in the BottomNavigationView can have those arguments.
I had to use all the legacy code of NavigationUI just to change this section from null to my Bundle arguments:
fun onNavDestinationSelected(... , bundle: Bundle? = null){
...
navController.navigate(item.itemId, bundle, options)
}
Dear Developers,
I have a problem which related keeping data.
When user click home tab again fragment is re-created again and data is loaded again.
I'd like to keep data previously same Youtube app.
Could you have any solution for this problem with Navigation?
Thank you very much for your tuts.
Step10 DeepLinkAppWidgetProvider's code is not Kotlin.
Add a Deep Link
We'll use the NavDeepLinkBuilder to hook up an app widget to a destination.
Open DeepLinkAppWidgetProvider
Add a PendingIntent constructed with NavDeepLinkBuilder:
DeepLinkAppWidgetProvider
Bundle args = new Bundle();
args.putString("myarg", "From Widget");
PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
.setGraph(R.navigation.mobile_navigation)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent();
remoteViews.setOnClickPendingIntent(R.id.deep_link, pendingIntent);
I think It's needs to replace Kotlin's code
Clicking on the deep link widget on the homescreen does not open up the android fragment - it doesn't seem to do anything.
I have uncommented the code referred to in this step in the DeepLinkAppWidgetProvider.kt file within the TODO comments (which is incorrectly labelled as Step 11 in the code) - see below - but perhaps there is a step missing?
val args = Bundle()
args.putString("myarg", "From Widget")
// TODO Step 11 - construct and set a PendingIntent using DeepLinkBuilder
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.mobile_navigation)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent()
remoteViews.setOnClickPendingIntent(R.id.deep_link, pendingIntent)
// TODO ENDSTEP 11
This code lab uses old api libraries, which doesn't include for instance app:argType change on navigation.
It should be migrated to androidx to keep up with latest framework changes
When changing orientation with open fragment. The application loops. The same fragment is started and restarted eternally.
For step 8 as of master 2bbc0ac:
the link to safe args goes to the overview of the documentation not the safe args section
1.1. current link: https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#Safe-args
1.2. correct link: https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#Safe-args
step 8 does not include the safe calls for arguments in the repository's code as the screenshot does, neither does the code below the screenshot.
the codelab does not include the ktx option as instructed by the documentation:
3.1. "In your receiving destination’s code, use the getArguments() method to retrieve the bundle and use its contents. When using the -ktx dependencies, Kotlin users can also use the by navArgs() property delegate to access arguments."
This one is not about the codelab, but the documentation itself. It suggests doing this:
val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
v.findNavController().navigate(action)
but as far as I understood it is not possible to pass the argument value directly into the action.
It should do as the codelab instructs and add the value into the argument from the action:
val action = HomeFragmentDirections.nextAction()
action.setFlowStepNumber(1)
findNavController().navigate(action)
Hi,
I'm not sure if I'm missing something but when I create a navigate click listener using a destination instead of an action, the intent doesn't work.
Using Navigation.findNavController(view).navigate(destinationId) works well.
Thanks
Under Using NavigationUI
, there's only two steps showing how to update the drawer and bottom navigation along with verifying that these menu items are shown when running the app. But, the actual implementation of the navigation from these items are missing.
The app structure used in the codelab implements the toolbar as fixed chrome (outside the fragment in navigation_activity.xml) but shows how flexible it can still be depending on the context - the title/label and menu items and options can change with each fragment destination.
However I noticed when you navigate to the settings fragment that the settings overflow is still shown in the toolbar. It probably doesn't make sense to have it there though as the user is already in settings?
How would you remove the settings overflow in this case?
As per the documentation, Directions classes are generated for every distinct destination with actions.
Suppose, There are three fragments FragA(with no argument), FragB( with one argument), FragC(with two argument).
In the navigation graph, create two instances of Frag A , single instance of Frag B , single instance of Frag C.
From first instance of Frag A create an action named "action_next" to Frag B.
From second instance of Frag A create an action named "action_next" to FragC.
Build the project and it will generate Direction class for Frag A. Only, single "ActionNext" method is getting generated instead of two.
Since there is only one "ActionNext" method so it should behave as per the context in which it is being used; but it appears that static code of direction class is not handling it right now.
Please fix bug with stubs http://prntscr.com/jgrbso http://prntscr.com/jgrc7i http://prntscr.com/jgrdge x64. Thanks for help.
I have navigation graph like this:
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_nav"
app:startDestination="@id/collectionFragment">
<fragment
android:id="@+id/collectionFragment"
android:name="com.antanassepikas.navbug.CollectionFragment"
android:label="fragment_collection"
tools:layout="@layout/fragment_collection" >
<action
android:id="@+id/action_collectionFragment_to_viewFragment"
app:destination="@id/viewFragment" />
</fragment>
<fragment
android:id="@+id/viewFragment"
android:name="com.antanassepikas.navbug.ViewFragment"
android:label="fragment_view"
tools:layout="@layout/fragment_view" >
<action
android:id="@+id/action_viewFragment_to_editFragment"
app:destination="@id/editFragment" />
</fragment>
<fragment
android:id="@+id/editFragment"
android:name="com.antanassepikas.navbug.EditFragment"
android:label="fragment_edit"
tools:layout="@layout/fragment_edit" >
<action
android:id="@+id/action_editFragment_to_viewFragment"
app:destination="@id/viewFragment"
app:popUpTo="@+id/viewFragment"
app:popUpToInclusive="true" />
</fragment>
</navigation>
Note that the last action has
app:popUpTo="@+id/viewFragment"
app:popUpToInclusive="true"
When navigated back from the last action this should open fragment previous to viewFragment instead of whatever the actual backstack is - And it does just that.
However event though @+id/collectionFragment after "Back Button" is opened and visible, further navigation actions cause crash.
java.lang.IllegalArgumentException: navigation destination com.antanassepikas.navbug:id/action_collectionFragment_to_viewFragment is unknown to this NavController
at androidx.navigation.NavController.navigate(NavController.java:669)
at androidx.navigation.NavController.navigate(NavController.java:628)
at androidx.navigation.NavController.navigate(NavController.java:616)
at com.antanassepikas.navbug.CollectionFragment$onCreateView$$inlined$apply$lambda$1.onClick(CollectionFragment.kt:17) at android.view.View.performClick(View.java:6891)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26083)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I think this has to do something with destination not being changed correctly, because when printing out what destinations change during this action cycle cycle this is what I see:
0 - com.antanassepikas.navbug:id/collectionFragment // when collection fragment is opened by default
1 - com.antanassepikas.navbug:id/viewFragment // when navigating from collection to item
2 - com.antanassepikas.navbug:id/editFragment // when navigating from item view to item edit
3 - com.antanassepikas.navbug:id/viewFragment // when navigating from item edit to item view
4 - com.antanassepikas.navbug:id/collectionFragment // this destinations happens automatically
5 - com.antanassepikas.navbug:id/viewFragment // this destinations happens automatically
At this point viewFragment is open and when "Back Button" is clicked collectionFragment is opened which is what is to be expected, but now when trying to opening another item a crash happens.
I created sample project where this is reproducible https://github.com/sepikas/navigation-bug
can you help me?
Is there any specific reason why this works:
view.findViewById<Button>(R.id.navigate_dest_bt)?.setOnClickListener( Navigation.createNavigateOnClickListener(R.id.flow_step_one, null) )
But this does not:
navigate_dest_bt.setOnClickListener { Navigation.createNavigateOnClickListener(R.id.flow_step_one, null) }
After checking out the project, the code compiles and builds - but receive Unresolved Reference: R for all files that use it.
Tried the following:
resources:
https://stackoverflow.com/questions/17421104/android-studio-marks-r-in-red-with-error-message-cannot-resolve-symbol-r-but
https://stackoverflow.com/questions/51621301/android-studio-3-1-3-unresolved-reference-r-kotlin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.