Android realizes automatic login and remembering user name and password through SharedPreferences

Recently, the Android project needs an automatic login function. After completion, I would like to summarize that this function depends on SharedPreferences.

Introduction to SharedPreferences

SharedPreferences is also a lightweight data storage method. Its essence is to store key value pair data based on XML files. It is usually used to store some simple configuration information. Its storage location is / data / data / < package name > / shared_ Prefs directory. The SharedPreferences object itself can only obtain data and does not support storage and modification. The storage and modification is realized through the editor object.

SharedPreferences usage example: remember the user name and password and log in automatically

After you have a general understanding of sharedpreference, let's take an example of automatic login by remembering user name and password:

Screenshot of page layout:

Generated profile location and code

The specific code of userinfo.xml is as follows:

The above is what Xiaobian introduced to you. Android realizes automatic login and remembering user name and password through SharedPreferences. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>