In my project, I have created a custom dialog inside which, I have a color palette that is initialized with a particular color(say Yellow) already checked. If I click on any color(say Blue), a tick image will come on top of the Blue color and the tick image from the previously checked color(Yellow) will be removed. Now, if I am rotating the emulator screen, the dialog is getting revert back to its initial state (with Yellow color checked). So, how can I save the state of the dialog?
Asked
Active
Viewed 34 times
1

zhangxaochen
- 32,744
- 15
- 77
- 108

anshulgoel72
- 61
- 1
-
hi@anshulgoel72,Could you please post some code ? Let me check the info to see the problem. – zhangxaochen Aug 04 '21 at 06:08
1 Answers
0
Based on the usecase specified, you may use Preferences class in HarmonyOS (ohos.data.preferences.Preferences) to save the color integer that was recently selected by the user when there is a configuration change like rotation of the screen or device language change.
- Use
preferences.putInt(key, value);
to store the value before the dialog is going to be destroyed.
- Use
preferences.getInt(key, DEFAULT_VALUE);
to retrieve the value when the dialog is recreated after being destroyed due to configuration change.
For more information, please refer the documentation

Samuel
- 36
- 3