Android Jetpack Navigation Component too slow. What's the problem?
Asked Answered
S

1

6

Today I was changing from ViewPager to Navigation Component (with Bottom Navigation View) on my Android project. The problem is that, when using ViewPager all is fast as lightning but using Navigation Component it's very laggy (2 seconds later after you pressed the view appears and specially with RecyclerView fragments).

Is there any way to pre-load fragments and improve transitions?

Thanks in advance !


MainActivity.java

NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupWithNavController(binding.bottomBar, navController);
Sorrel answered 25/4, 2020 at 23:6 Comment(2)
With a viewpager you can preload the neighboring screens, while the nav component will create the fragments after you've selected it. So it looks like the lag is in the inflation of your fragments, you may be doing too much work on inflation.Consecration
Yes but, when using a ViewPager there's no lag even when I start the app (that's when I suppose the fragment inflates). There's a huge difference on UX.Sorrel
G
0

I too had the same issue. I believe its a bug in their latest dependency.

Changing to androidx.navigation:navigation-fragment-ktx:2.3.4 and androidx.navigation:navigation-ui-ktx:2.3.4 solved my issue.

Might also work for higher versions than 2.3.4. I haven't checked yet.

German answered 3/6, 2022 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.