简体   繁体   中英

Maintaining Session or State for username in android application

In web development we have usually seen we use session or cookies to maintain username, and it remains there unless we destroy it or server removes it, i am making an android application, i have a login and a password, what i want is to just, if i get logged in, it should save my username in something similar to session or cookie, and if i move anywhere among intents or screens, it should not be destroyed and i must be able to access it any where. What's the best approach to implement it?

成功时,将您的用户名和密码或会话ID存储在SharedPreferences

It depends how permanently persisted you want to store the information. If you need it to be remembered after the app is closed you'll need a persitant store but you should ensure that the password is encrypted.

If it's only for the running life of the app you could hold the information in static properties on a class.

The best way is to store in in SharedPrefences. See this tutorial . Also use MD5 or SHA algorithm for encrypting. See this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM