简体   繁体   中英

Best way to save a little amount of data

I'm currently developing an Android application where OAuth will be in use. In order to use OAuth, I need to be able to save the consumer's private key to access the protected resources. My question is, where would I want to save this tiny piece of data? I know that for most Android applications, data would be stored in a SQLite database. But for only a little bit of information, a string containing random letters and numbers, would SQLite be the best way to go? Or would it just be better to write the data to a file and save it on the file system? I don't know what the best practice for this would be, so hopefully I'll be able to get some insight.

Thanks a bunch guys!

I would save it in a file on the internal storage or in shared preferences .

Never the less you should encrypt the key for security reasons. On a rooted oder developer device it is no problem to access any file on the system.

You have a lot of choices:

http://developer.android.com/guide/topics/data/data-storage.html

However, if you just want to save one String (the OAuth key), I would suggest shared preferences. Example:

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("oauthKey", yourOAuthKey);

// Commit the edits!
editor.commit();

SharedPrefs is much easier to work with than an sqlite database - especially for something so simple as you describe.

I guess a SharedPreference would do just fine.

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