开发者

Best way to save a little amount of data

开发者 https://www.devze.com 2023-03-08 15:23 出处:网络
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

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 SQLi开发者_开发百科te 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!


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();


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消