Skip to content

Fix: User input text is lost on screen rotation#14

Open
AndreSand wants to merge 1 commit into
android:mainfrom
AndreSand:fix/agent-text-field-state
Open

Fix: User input text is lost on screen rotation#14
AndreSand wants to merge 1 commit into
android:mainfrom
AndreSand:fix/agent-text-field-state

Conversation

@AndreSand

Copy link
Copy Markdown
  • Add OnMessageTextChanged to AgentUiEvent to capture user input.
  • Migrate message text state from local Compose state to the ViewModel, utilizing SavedStateHandle for state persistence across configuration changes.

What I have done and why
Fix #13

Video fix:
https://github.com/user-attachments/assets/00c9b9ce-e24a-437d-bb81-e314438afe22

- Add `OnMessageTextChanged` to `AgentUiEvent` to capture user input.
- Migrate message text state from local Compose state to the ViewModel, utilizing `SavedStateHandle` for state persistence across configuration changes and process death.
- Reset the message text in the ViewModel when an `OnSendMessage` event is processed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the messageText state in the AgentDemo screen, moving it from local UI state to the AgentDemoViewModel backed by SavedStateHandle to ensure state persistence across configuration changes. The reviewer suggested adding unit tests to verify that the view model correctly updates and clears this state.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +167 to +169
is AgentUiEvent.OnMessageTextChanged -> {
savedStateHandle[KEY_MESSAGE_TEXT] = event.text
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Consider adding unit tests in AgentDemoViewModelTest.kt to verify that OnMessageTextChanged correctly updates the savedStateHandle and that OnSendMessage clears it. This ensures the state persistence logic remains robust against future refactoring.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agent App Text input state lost on screen rotation

1 participant