Detailed explanation of the four operating modes of Android SharedPreferences

Detailed explanation of Android SharedPreferences

There are two ways to get SharedPreferences:

1 call the getsharedpreferences() method of the context object

2 call the getpreferences () method of the activity object

Differences between the two methods:

The SharedPreferences object obtained by calling the getsharedpreferences() method of the context object can be shared by other components under the same application. The SharedPreferences object obtained by calling the getpreferences() method of the activity object can only be used in this activity

There are four modes of operation for SharedPreferences:

Save data to SharedPreferences:

Read data from SharedPreferences:

Thank you for reading, hope to help you, thank you for your support to this site! If you have any questions, please leave a message or go to our community to exchange and discuss, and make common progress!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>