My application requires the user to login on their first visit, and then it stores this in SharedPreferences for any future times the application is launched.
I’m trying to implement a sign out feature, and I’m wondering what the best way would be.
As of right now, my LoginActivity and SignOutActivity are separate since they occur on different screens. Ideally, I’d like to be able to store the preferences in a way that both of these activities can access the login data and have it still be secure. How would all of you suggest I handle this?
Either just use the default SharedPreferences or get the SharedPreferences with the same name in both activities; the whole point of them is that they’re shared 🙂 I’m a little worried that you think
SharedPreferencesare actually secure or isolated; they’re not. Anyone with root permission can read them (although other apps without root permission can’t by default). If you’re storing passwords or anything like that, encrypt them.There are 3 modes for SharedPreferences:
MODE_PRIVATE,MODE_WORLD_READABLEandMODE_WORLD_WRITEABLE.MODE_PRIVATE, the default and the most restrictive one, still allows free access to the Preferences to any activity in your own app (or any other app you create with the same user ID).