1

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?

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108

1 Answers1

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.

  1. Use
preferences.putInt(key, value);

to store the value before the dialog is going to be destroyed.

  1. 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