Android icon indicating copy to clipboard operation
Android copied to clipboard

[Bug] App Returns to Start Page After Rotation

Open ImDiM opened this issue 11 months ago • 5 comments

Describe the bug

Choose Your Browser page Returns to Start Page After Rotation

How to Reproduce

  1. Tap Let's do it!
  2. Observe that the Choose Your Browser button is visible.
  3. Rotate the device 90° to landscape mode.
  4. In landscape mode, the app returns to the start page.
Image Image Image

Expected behavior

After rotating 90°, the app should remain on the Choose Your Browser page.

Environment

- DDG App Version:5.225.0 (52250000)
- Device: Pixel 6a
- OS: Android 13

ImDiM avatar Dec 30 '25 10:12 ImDiM

Thank you for opening an Issue in our Repository. The issue has been forwarded to the team and we'll follow up as soon as we have time to investigate. As stated in our Contribution Guidelines, requests for feedback should be addressed via the Feedback section in the Android app.

github-actions[bot] avatar Dec 30 '25 10:12 github-actions[bot]

I'd like to contribute to the project by fixing this bug. Is it available? Thanks in advance

Tiago-Vier-Preto avatar Jan 03 '26 17:01 Tiago-Vier-Preto

Thank you @Tiago-Vier-Preto. Someone will take a look at the it.

0nko avatar Jan 07 '26 19:01 0nko

Hi @Tiago-Vier-Preto, @0nko,

your solution is great! I was also contributing in fixing the issue and my way to solve this was to work with saving the current dialog type and saving it in fragment's instance when changing orientation:

 override fun onSaveInstanceState(outState: Bundle) {
        lastDialogType?.let {
            outState.putSerializable(LAST_DIALOG_TYPE_KEY, it)
        }
        super.onSaveInstanceState(outState)
    }

This would allow the fragment to know exactly what dialog was showing before the configuration change in the "onViewCreated" method:

if (savedInstanceState != null && !savedInstanceState.isEmpty) {
            val restoredDialogType = savedInstanceState.getSerializable(LAST_DIALOG_TYPE_KEY) as? PreOnboardingDialogType
            scheduleWelcomeAnimation(requiresLoadDialog = false)
            restoredDialogType?.let {
                configureDaxCta(it)
            }
        } else {
            setupWelcomePage()
        }

My only structural UI change was to restore the welcoming animation without invoking the "loadDaxDialog" method in ViewModel:

private fun scheduleWelcomeAnimation(startDelay: Long = ANIMATION_DELAY, requiresLoadDialog: Boolean = true) {
        ViewCompat.animate(binding.foregroundImageView)
            .alpha(MIN_ALPHA)
            .setDuration(ANIMATION_DURATION).startDelay = startDelay
        welcomeAnimation = ViewCompat.animate(binding.welcomeContent as View)
            .alpha(MIN_ALPHA)
            .setDuration(ANIMATION_DURATION)
            .setStartDelay(startDelay)
            .withEndAction {
                if(requiresLoadDialog) {
                    viewModel.loadDaxDialog()
                }
            }
    }

I think that's a great question for an interview for an Android Engineer, on how to handle screen orientation changes 🤣

What do you think? Happy to discuss the trade-offs of both approaches if useful!

Either way, glad the issue is getting fixed 👍

PaoloMazza1995 avatar Jan 10 '26 17:01 PaoloMazza1995

Hi @PaoloMazza1995, thanks for the review! 🙏

Your solution definitely works too! I personally leaned towards the StateFlow approach because it keeps the Fragment (UI) logic lighter and avoids the overhead of serialization during rotation.

Regarding system-initiated process death (which onSaveInstanceState handles): I felt that for this specific Welcome flow, restoring the exact state after the app is killed isn't strictly necessary. If the user returns after the process is killed, restarting the onboarding feels acceptable.

I also tried to follow the official recommendations regarding the performance. As noted in the docs:

Image

[Link]

ViewModel is ideal for storing and managing UI-related data while the user is actively using the application. It allows quick access to UI data and helps you avoid refetching data from network or disk across rotation, window resizing, and other commonly occurring configuration changes.

But you are totally right, handling screen orientation is always a nightmare for the interviewee! 🤣 Thanks again! 🥶

Tiago-Vier-Preto avatar Jan 13 '26 21:01 Tiago-Vier-Preto