When sharing SharedPreference among activities, pay more attention!

Generally, we update SharedPreference by its editor;

Then we use putXXX to update the value in it.

Finally, commit the change to save it to file. We often do it in onStop() or onDestroy()

It’s OK in one activity. But if multiple activities get the same preference, you need pay more attention. Since after committing, the previous settings, especially updated by other activities, may be lost. You may need a class to do updating/committing if you only want one preference. Or you can have multiple SharedPreference.

发表评论

电子邮件地址不会被公开。 必填项已用*标注