Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MaterialDatePicker] Selected month is lost when app returns from background #4539

Open
mtotschnig opened this issue Jan 16, 2025 · 2 comments

Comments

@mtotschnig
Copy link
Contributor

mtotschnig commented Jan 16, 2025

Description: Issue can be reproduced with Catalog app, as seen in attached recording

  1. Open DatePicker, and navigate to month in the past or in the future.
  2. Put app into background and then bring to foreground
  3. DatePicker selection moves back to current month (or the one it was opened with initially)

Expected behavior: State of the component should be maintained.

The problem only happens in background/foreground use case. When device is rotated, the state is correctly maintained.

Android API version: Observed on multiple versions, e.g. 30 and 35.

Material Library version: Catalog app built from HEAD on master branch (690bbfc). Also observed with 1.12.0

Device: Observed on multiple devices, e.g. Android emulator, Pixel 6a

As a user of my app has reported (mtotschnig/MyExpenses#1626), this has important UX implication: User navigates to a given month, and before selecting the day, they need to verify information in a different app, and when returning to my app, the month they already have selected, is lost.

Screen_recording_20250116_235244.mp4
@mtotschnig mtotschnig added the bug label Jan 16, 2025
@mtotschnig
Copy link
Contributor Author

On a technical level, the problem seems to be caused by the fragments being recreated every time in onStart. Reusing the existing fragments seems to solve the issue:
mtotschnig@48d4f39

@mtotschnig
Copy link
Contributor Author

If someone from the team confirms that my solution is valid, I can open PR.

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

No branches or pull requests

2 participants