Jet pack navigation component get deep links programmatically - android

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

Related

Deeplinking with Navigation component with Individual Stack

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

Navigating with Android Navigation Drawer

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!

Managing multiple hierarchies using Fragment Manager and DrawerLayout

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.

How to implement a tutorial with Drawer Navigation

I'm not an Android ninja developer and I'd like to implement an app which has a Drawer Navigation and includes a tutorial.
Basically if you are in "My App" you should see a 5-6 steps tutorial.
The question is:
How can I implement that app?
I'd like to know how to organize it and which components I should use.
I'd really appreciate a step-by-step guide.
Thanks a lot.
This is a weird mockup of what I'm trying to implement :)
You can make an activity on top of drawer and then you can simply put view pager in Activity for tutorial. When user will finish tutorial you can move user to Drawer Navigation.
So you can use following method.
Check if user is visiting application for first time then show tutorial activity then move to Navigation Drawer. If user is visiting application for second time or more then you can directly move user to Navigation Drawer and start app.
If your tutorial is for the overall app, Jayesh's answer is right: you should put it in a separate Activity.
If the tutorial only demonstrates part of your app, i.e. only the drawer your are in, I suggest you use:
One MainActivity with a DrawerLayout. The latest SDK tools have a real cool template for NavigationDrawer, that will save you a lot of time!
In your TutorialFragment, write a layout with a ViewPager and the fixed bar at the bottom.
Add pages for your tutorial to this ViewPager.

History back navigation using ng-include

I started to develop a single page web app with angularjs and now I'm defining the navigation. So, I end up using 2 levels of navigation:
1st level: Main navigation using ng-view.
2nd level: SubView navigation with the top and bottom bars using ng-include.
This is our iphone scenario:
The iphone scenario seems ok for me because we control all navigation with our buttons.
But, now lets think in android scenario where the user can use the history back button(physical button) to navigate back. How can we support it if we use ng-include for the subnavigation?
Thanks in advance
You could add a parameter to your URL to make it work with Android history.
#/main?page=1
#/main?page=2
Then use that to control the state of your app, and then android back button will work.
You can set url parameters with $location.search:
$location.search('page', 4);
$location.search docs: http://docs.angularjs.org/api/ng.$location#search
And one more thing: You'll want to add reloadOnSearch: false option to your $routeProvider.when() declaration for your view. By default, the whole view reloads when you change a query parameter with $location.search(). Setting that to false will make it not reload, which is what you want in this case:
$routeProvider.when('/main', { reloadOnSearch: false });
reloadOnSearch docs: http://docs.angularjs.org/api/ng.$routeProvider#when

Categories

Resources