If I want to store the username and password to be used inside an Android application, what is the best way to do it? Is it through the preferences screen (but what if the user misses this?), or pop up a dialog box and ask the user for the credentials? If so, I do have to maintain state for the application. How would I do this?
Android: Storing username and password
androidauthenticationcredentialsstorage
Related Topic
- Android – the difference between “px”, “dip”, “dp” and “sp”
- Android – Is quitting an application frowned upon
- Mongodb – How to secure MongoDB with username and password
- Git push requires username and password
- Java – Proper use cases for Android UserManager.isUserAGoat()
- Android – How to “select Android SDK” in Android Studio
- Git – How to save username and password in Git
Best Answer
Most Android and iPhone apps I have seen use an initial screen or dialog box to ask for credentials. I think it is cumbersome for the user to have to re-enter their name/password often, so storing that info makes sense from a usability perspective.
The advice from the (Android dev guide) is:
Using the AccountManger is the best option for storing credentials. The SampleSyncAdapter provides an example of how to use it.
If this is not an option to you for some reason, you can fall back to persisting credentials using the Preferences mechanism. Other applications won't be able to access your preferences, so the user's information is not easily exposed.