How to set the check box's checked option persistent,while user switches from one activity class to another
i am designing a simple android app,which has a check box displayed in the list view and my application is g开发者_如何学编程iving a alarm when the corresponding check box is checked.But while i am moving from that screen to my home screen and again coming back to my page containing the check box it doesn't show that which check box i checked previously.
Please help me regarding this topic, than x in advance..
Probably you are setting it as checked/unchecked somewhere (like in the onResume()
or elsewhere) so it's state is reset each time you enter this activity.
If the checked state must persist between app runs, you could store the checkbox state in a SharedPreference and in the onResume()
use the setChecked method with the value of the preference...
Else you can try not to overwrite anywhere the checkbox state or store it in a class field or something to reset it to the desired value when the activity return to front
You need to save the setting to SharedPreferences
. In the onPause()
method of your activity, save the setting. You can then read the preferences in onResume()
and re-populate your UI. Any other Activity
or Service
can then read the setting from the preferences and take action accordingly.
精彩评论