GeekedOut
GeekedOut

Reputation: 17185

How to maintain persistent data throughout android app lifetime?

I was able to get the user to log in, and I want to keep them logged in.

As I understand it, Android enables you to set cookies. I also understand that there is some ability to write to a local file and keep some information persistent there.

What I am wondering is which approach is best when? Is there a best practice for this scenario? Also links to good tutorials would be appreciated.

Thanks!

Upvotes: 0

Views: 397

Answers (2)

T Percival
T Percival

Reputation: 8684

Check out Data Storage in the Dev Guide. It sounds like Shared Preferences are what you're after.

Upvotes: 2

Joe Malin
Joe Malin

Reputation: 8641

This depends on what you mean by "logged in". Although that's "persistent data", it's really more a matter of maintaining credentials. You may want to look at AccountManager. Credentials demand a much higher level of security than other persistence patterns.

I wouldn't use cookies. That's web technology, and while Android enables them, they're clunky for what you're trying to do.

There's no best practice for doing this because different systems have different ways of doing authentication. For example, OAuth2 (used by many Google web services) uses authtokens that you can handle with AccountManager and Authenticators. OAuth2 support on Android allows you to get credentials once, and then keep them persistent across applications in the system while maintaining security.

However, if you're not using OAuth2 you probably can't use this pattern.

If you can provide more specifics, you'll probably get more help.

Upvotes: 1

Related Questions