question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dot indicator resets to the first page after the activity is rotated

See original GitHub issue

As the title states. I set the ViewPager2 object for the SpringDotsIndicator in the onCreate() method of my activity, and don’t do anything else with the SpringDotsIndicator:

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        ...
        final ViewPager2 viewPager = findViewById(R.id.tutorial_pager);
        final FragmentStateAdapter pageAdapter = new MyPageAdapter(this);
        viewPager.setAdapter(pageAdapter);
        final SpringDotsIndicator dotsIndicator = (SpringDotsIndicator) findViewById(R.id.spring_dots_indicator);
        dotsIndicator.setViewPager2(viewPager);
        ...

It behaves correctly normally. However, if I’m on e.g. my third fragment and rotate the screen, when the activity is recreated the fragment shown in the new orientation is still the third one, but the dot indicates that we are on the first fragment.

As soon as I slide the fragment slightly the dot catches up and goes to the correct position.

Is this a bug or am I missing some code in order to handle these cases?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tommybuonomocommented, Apr 30, 2022

Hello @nachogoro 👋 I am sorry for this very late reply, but this issue will be fixed in the coming 4.3 version

0reactions
tommybuonomocommented, Apr 30, 2022

Hello, thanks for your contribution ! This issue is now fixed in the new version 4.3 Thanks 🔥

Read more comments on GitHub >

github_iconTop Results From Across the Web

Losing data when rotate screen - android - Stack Overflow
By default, when the screen is rotated your Activity is killed and restarted. To make sure no data is lost, you need to...
Read more >
The activity lifecycle | Android Developers
A user expects an activity's UI state to remain the same throughout a configuration change, such as rotation or switching into multi-window ...
Read more >
Surviving Configuration Changes in Android
When you rotated the screen, the app lost the count data because it recreated the activity to adapt to the new orientation. Your...
Read more >
ViewPager with FragmentPagerAdapter - CodePath Cliffnotes
The first approach is to have the page display a fragment container that switches between multiple child content fragments as outlined in this...
Read more >
Handling Orientation Changes on Android - Medium
When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found