Skip to content

Conversation

@Kota-Jagadeesh
Copy link
Collaborator

@Kota-Jagadeesh Kota-Jagadeesh commented Jan 5, 2026

Description (required)

What changes did you make and why?

  1. Implemented State Restoration in SearchActivity: added tha onSaveInstanceState to track the current media position and updated onCreate to restore the media detail view if a position was previously saved. This replaces the previous temporary fix in onResume which forced a back-press on rotation.
  2. Synchronized MediaDetailPagerFragment: Updated the fragment to save and restore its internal ViewPager current item index.
  3. Improved UX & Navigation: By using binding.root.post for restoration, I ensured the UI is fully laid out before re-opening details, preventing crashes and ensuring the user stays on the same image they were viewing before rotating the device.
  4. Cleaned up Fragment Stack: Removed the onBackPressed() call from onResume() which was an anti-pattern causing the fragment back-stack to increase incorrectly.

Tests performed (required)

Tested ProdDebug on Redmi Note 13 Pro with API level 35.

  • Verified that rotating from Portrait to Landscape while viewing an image detail does not return the user to the search results list.
  • Verified that the Back button correctly returns the user to the search results after a rotation occurs.
  • Verified that isFeaturedImage and editable flags are preserved after rotation, keeping menu items consistent.

Part of issue #6508

@github-actions
Copy link

✅ Generated APK variants!

outState.putBoolean("isFeaturedImage", isFeaturedImage)
// save the current item position so it can be restored after rotation
if (binding != null) {
outState.putInt("current-page", binding!!.mediaDetailsPager.currentItem)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering: if we make binding null in onDestroy to fix memory leaks, will this always be null and never run? 🤔

What alternatives do we have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants