I have two urls which falls under the same deep link like below :
xxx.yyy.zzz/pages
xxx.yyy.zzz/how-deeplinks-work-exactly
Now the first one is a list of pages which goes to a fragment which lists the list of pages and second goes to a fragment which shows the details of that page.
Scenario :
https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample
I am following the above sample for having independent stacks for each tab.
When I have two different deep links for the above two links, it navigates to both the fragments. Like when I open the app with xxx.yyy.zzz/pages url it opens both the PagesFragment and DetailFragment one after another. So when I press back button from PagesFragment it navigates back to DetailFragment.
Now how do I handle these two scenario with deep links. If have both the deep links setup it navigates to both the screens one by one. I know I can change the path and add a prefix the page detail url(xxx.yyy.zzz/page/how-deeplinks-work-exactly), but is there anyway I can intercept the parsing logic or add some exclude condition to achieve this without changing the url scheme?
Edit : This is likely an issue with the Navigation logic (NavigationExtensions.kt) written for having individual stack.
You shouldn't use NavigationExtensions.kt anymore, instead increase your navigation component library version. Check this article out: https://medium.com/androiddevelopers/navigation-multiple-back-stacks-6c67ba41952f
Perhaps upgrading the lib version also changes the behaviour of your app with respect to the deep links
Related
I'm programming deep link behavior where a particular link navigates the user to a video. In the normal flow, the user navigates to this video through a course details fragment containing a list of the videos.
However, the deep link flow obviously skips this screen, meaning that when the user backs out of the video, they are sent directly to home. I'd like to insert the course details screen into the backstack so that when the user backs out of the video, they are instead redirected to the course detail screen. What is the best way of doing this?
At the moment, my deep link code executes a navigation to course details screen right before the navigation to the video occurs.
You can make transaction fragments easier by using the following class (which is done with 4 methods in total) For more readability and simplified transaction.
https://github.com/mahditavakoli1312/FragmentTransaction---mahdi-tavakoli
I am using the Navigation Component in my app. I have created the graph successfully and linked it with a bottom navigation bar. I have also added deep links to my fragments to which i can redirect successfully. My question is, if it is possible to get the declared deep links of a fragment in the graph programmatically. The reason i want to do so is to check if that fragment is already visible in the screen before loading it again through the deep link
Found a solution.
val isCurrentFragmentWithDeepLink = navController.currentDestination?.hasDeepLink(uri) ?: false
I am checking if the current fragment destination has that deep link or no. So assuming that the deep links are unique for each fragment i am not re navigating to it
i am creating a diary application that has a page for showing: diary entries, new diary entries and events that the user has coming up, my application will use a database to store entries and display.
I was wondering how best to go about navigation in my app, as i wanted to use a navigation drawer. Can navigation drawer's be used to navigate between activities and if not how would i implement fragments to be handle the functionality i want?
A NavigationDrawer is typically used to navigate between a few Fragments. A main Activity is used to handle user interaction with the NavigationDrawer and will typically attach the corresponding Fragment to a container within the Activity.
With that being said, your best bet would be following the full tutorial posted on the Android developers webpage. The tutorial contains each step necessary to successfully implement a NavigationDrawer in your application. In addition, you may download the completed and functional project from that tutorial and import it into your IDE.
Good luck and happy coding!
Hi all android noob here.
One of the difficulties I have in android is choosing what to load should I load the fragment or should I fire an activity?
My module will from a recyclerview, once user clicks on the item it will take them to another screen which contains a viewpager with two tabs news and topics.
for this account, should I load it via fragment or should I start another activity?
Additional question:
in what terms should I start an activity?
in what terms should I use fragment for hoping on the next screen?
Thanks.
First of all see the follwing official documentation: Navigating between sibling screens
There are no ideas about what should you use activity or fragment, but if you open a fragment you have to use buttons "Up" and "Back" and then you press them you should go back to the previous activity at the same state. So if you use the fragment you have to override a lot of code for appropriate working code, so in my opinion it's better way to start new activity.
I have an app that is using a DrawerLayout and each item in the drawer will load a Fragment. The structure looks like:
News -> News Story
Photos -> Gallery -> Photo
Events -> Event
Directory -> User Type -> User Profile
Each top level is an item in the Drawer, tapping one will take you to that fragment and you can go deeper into that section by adding additional fragments on the stack, e.g. navigating from Photos to a Gallery to a photo in that gallery.
It gets confusing when I need to manage the navigation of each of these sections as individual stacks. On iOS I would use a UINavigationController for each section so that I could manage either separately. But on Android I am not sure how to do this. It is almost like I need to have multiple Fragment Manager instances. Without this, I feel I will run into issues when:
A user is deep into the News stack then switches to Photos, they navigate deep into that stack, but want to return to where they were in the News section. How can they return to that stack? And, navigate back up the News stack?
This seems like a major design issue with Android, unless I am missing something. Any ideas on how to solve this?
EDIT:
Basically I want what they showed at Google I/O:
https://www.youtube.com/watch?v=XpqyiBR0lJ4
I just built an app with this design. I just kept adding fragments to the stack when the user was in 'News' or any sub category of 'News'. If the user navigated to 'Photos' I would just pop all of the fragments from stack with:
getFragmentManager().popBackStackImmediate(null,FragmentManager.POP_BACK_STACK_INCLUSIVE);
and start adding to the stack again. I'm not sure if this is the 'right way' but it worked fine for me. I would just log the last fragment they were viewing in 'News' and restore it when they return to 'News' if that's the behavior you are looking for.
I managed multiple categories/sub-cats just fine using one Activity.