0

In my application, my requirement is like I want checkbox to be checked for first time at the time of opening the app and after that I want that value to be retained till the app is unistalled from the device.

For this purpose I have used "Shared Preferences" to store the value on first time check. Till this point everything is fine.

When I press the "home" button and again accessing the app checkbox is in unchecked state. Now for this I have written code to check the checkbox in onResume, but when I close the apps in my system and reopen the app again checkbox is resetting to unchecked. I am not sure how to solve this.

I read the lifecycle of Android here.

After reading this I am assuming to write the checked code in onRestart but again not sure whether the approach is correct or not.

halfer
  • 19,471
  • 17
  • 87
  • 173
Siva
  • 9,159
  • 10
  • 36
  • 59

1 Answers1

1

I was able to solve my problem using the shared preferences... Initially I have declared the shared preferences wrong now code was working and also I have used onResume to reinitate the checked value.

Siva
  • 9,159
  • 10
  • 36
  • 59