android-navigation | Navigation library
kandi X-RAY | android-navigation Summary
kandi X-RAY | android-navigation Summary
android-navigation
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of android-navigation
android-navigation Key Features
android-navigation Examples and Code Snippets
Community Discussions
Trending Discussions on android-navigation
QUESTION
I am using Navigation component in my App, using google Advanced Sample(here). my problem is when going back to a fragment, the scrolling position does not lost but it rearranges items and moves highest visible items so that top of those item align to top of recyclerview. please see this:
before going to next fragment:
and after back to fragment:
this problem is matter because some times clicked item goes down and not seen until scroll down. how to prevent this behavior?
please consider:
this problem exist if using navigation component to change fragment. if start fragment using
supportFragmentManager.beginTransaction()
or start another activity and then go to this fragment it is OK. but if I navigate to another fragment using navigation component this problem is exist.(maybe because of recreating fragment)also this problem exist if using fragment in ViewPager. i.e recyclerView is in a fragment that handle with ViewPagerAdapter and viewPager is in HomeFragment that opened with Navigation component. if recyclerView is in HomeFragment there is no problem.
no problem with LinearLayoutManager. only with StaggeredGridLayoutManager.
there is not difference if using ViewPager2 and also FragmentStatePagerAdapter
I try to prevent recreate of fragment(by this solution) but not solved.
UPDATE: you can clone project with this problem from here
...ANSWER
Answered 2021-Jan-05 at 13:46The Navigation Component behavior is normal when you navigate from one fragment to another. I mean, onDestroyView()
method from the previous fragment is executed, so it means that your view is destroyed, but not the fragment. Remembering that fragment has two lifecycles one for the fragment and another one for the view, There was a video about it.
Also, there were issues registered in issue tracker in order to avoid this behavior in some cases and the GitHub issues:
- https://issuetracker.google.com/issues/127932815
- https://github.com/android/architecture-components-samples/issues/530
The problem is that when you have fragment that is heavy to recreate, is easier to do not destroy it and just add one fragment. So, when you go back it is not recreated. But, for this behavior is not part of navigation component.
Solutions
The easiest solution is to not use navigation component and work with the tradicional way, as you can see this works perfectly in you use case.
You can use the traditional way just for this use case, and use the navigation component for other cases.
You can inflate this view in an activity. So you are adding un activity
But if the previous tree options is not possible. You can try the following:
- If you are using viewModel, you can use SaveState. Basically, it can save the data from your fragment, it is like a map data structure, so you can save positions from your list or recycler view. When go back to this fragment, get the position from this saveState object and use
scrollToPosition
method in order to add the real position. - Recycler view have methods for restore positions. You can see the uses cases for that, because first you need the data and then add the real position, for more details you can visit this link. This configuration for recycler view is useful also when you lose memory and you need to recreate the recycler view with asynchronous data.
- If you are using viewModel, you can use SaveState. Basically, it can save the data from your fragment, it is like a map data structure, so you can save positions from your list or recycler view. When go back to this fragment, get the position from this saveState object and use
Finally, if you want to understand more about how fragment works with navigation component, you can see this link
QUESTION
I am implementing the mapbox maps and the mapbox navigation by using these imports:
...ANSWER
Answered 2021-Apr-21 at 01:22It's (fortunately) not too tricky to do - it's a matter of creating a new style (in styles.xml) for this purpose.
Something like this: (an excerpt from Mapbox's guides/documentation)
[style.xml]
QUESTION
I am basically getting a runtime error when using the below dependency:
...ANSWER
Answered 2020-Nov-30 at 13:30Replacing all the mapbox dependencies with this solved my problem :
QUESTION
So I have a menu item which has too much space between the icon and the text. The image here
How do I remove the space between the icon and the text?
Here is my menu.xml file:
...ANSWER
Answered 2020-Sep-24 at 13:42I found the solution. The image size needs to be bigger like 24x24.
QUESTION
I have a callback method in my fragment which gets called from it's ViewModel. It initializes the variable in the OnCreateView()
method of the fragment, but when the ViewModel calls it to use it, its null.
I am thinking that it has something to do with maybe the VM getting recreated somehow? I just can't seem to figure it out.
I am following this answer's of how the VM drives the UI. They provide Google's sample of a callback interface being created (TasksNavigator.java), Overriding the method in the View (TasksActivity.java), and then calling that method from the VM (TasksViewModel.java) but it doesn't seem to work for me.
Fragment
...ANSWER
Answered 2020-Sep-08 at 07:04Initiate ViewModel in below method of fragment
QUESTION
I am a noob at Kotlin/android and I am trying to make a sidebar(also called navigation drawer). I tried to follow this tutorial: https://medium.com/quick-code/android-navigation-drawer-e80f7fc2594f
and I soon had to import com.android.support:design
. I searched up the name of the library to get the latest version but found out the it was deprecated. It had been replaced with Jetpack. I tried finding it but couldn't find the android.support
Jetpack alternative anywhere. What is it? If there isn't, how do you create a navigation drawer with modern dependencies? Thanks.
ANSWER
Answered 2020-Aug-10 at 19:41Support design
has been deprecated. You need Material Components
.
In your app level build.gradle
file add
implementation 'com.google.android.material:material:1.0.0
.
Read more about it here https://material.io/develop/android/docs/getting-started
Note : Check for the current version
QUESTION
I've separated a feature from app
module into a Dynamic Feature Module (named dfm
).
The module works perfectly where I've followed all best practices and requirements. But one of the test cases in the androidTest which uses AndroidJUnit4
and Espresso does not work and fails and breaks while building at the task : mergeLibDexDebugAndroidTest
.
The project consists of:
app
module : Main moduletestlib
: Library module consisting few classes used for unit tests (Not used by the espresso test case that doesn't run)dfm
: Dynamic Feature Module where the espresso test case lies
There is no specific error but it just gives the following error message:
ANSWER
Answered 2020-Jul-24 at 01:05In the error log, we see the line:
QUESTION
I am following this tutorial: https://docs.mapbox.com/help/tutorials/android-navigation-sdk/
No matter what I do these packages cannot be imported.
...ANSWER
Answered 2020-Jul-13 at 15:19Apparently, the tutorial is missing about one attribute that has to be imported in the gradle. So,
Aside from adding:
QUESTION
I'm trying to follow this: https://developer.android.com/guide/navigation/navigation-ui along with a review of https://codelabs.developers.google.com/codelabs/android-navigation/#8 (although the second link is in Kotlin and I'm coding in Javascript) to implement an App in Android with navigation drawer on the left and a settings button (preferences) on the top right.
I'm using the NavigationUI with fragments for each option from the drawer and the settings.
My problem is that my settings fragment is not appearing. I think I'm nearly there, but despite reviewing several articles and questions cannot get it to work.
This code allows me to switch fragment from the nav drawer:
...ANSWER
Answered 2020-Jun-07 at 12:13You have different options:
Just define the SettingsFragment
in your navigation graph:
QUESTION
Please do not mark this as duplicate, I have read these SO question already but still, it is not working navigation component popUpTo bug Android navigation component popUpTo behaviour Android Navigation Component + Login Flow + Nested BottomNavigationView
I am using
...ANSWER
Answered 2020-May-08 at 16:51You're using the wrong id in your popUpTo
As per the popUpTo guide:
app:popUpTo
tells the Navigation library to pop some destinations off of the back stack as part of the call tonavigate()
. The attribute value is the ID of the most recent destination that should remain on the stack.You can also include
app:popUpToInclusive="true"
to indicate that the destination specified inapp:popUpTo
should also be removed from the back stack.
The popUpTo
should point to the destination that is already on the back stack that you want to pop off the back stack. Therefore if you want to pop everything up to the splashFragment
, you should use app:popUpTo="@id/splashFragment"
. If you want to pop everything up to and including the splashFragment
, then you should use app:popUpTo="@id/splashFragment"
and app:popUpToInclusive="true"
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install android-navigation
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page