views:

56

answers:

1

Hello,

I'm looking for a way in an Android application to store a password within the memory as long as the application is running (cf. different activities). I was first thinking about the SharedPreferences, but then it's saved in the flash memory, which isn't that good for a password, I guess.

I'm unsure, what's the best way. What would you recommend me?

A: 

I guess you have to consider what it really means for the application (or activity) to be running. If the user navigates away from your application, it could remain in memory or its process may be terminated to reclaim resources for foreground activities. This is all transparent to the user, since if they navigate back to your application and it was previously terminated it will be re-created for them.

Activity Life-Cycle

If the expectation is that the password will always be remembered until the user manually "exits", then I believe you must accept that the password could be written to persistent storage (if the process is killed, for instance). This doesn't mean that the password has to be stored in clear text. However, then you have the additional problem of storing the key used to protect the password.

Michael Petito