Reputation: 296
My android app is a news app that fetches JSON data as its content from a link.... I want the user to be able to store these contents on their android phone app directory for future viewing... Please how can I do this?
Upvotes: 0
Views: 1235
Reputation: 1248
Store data
SharedPreferences prefs = getSharedPreferences("DATA_FILE", 0);
SharedPreferences.Editor prefsE = prefs.edit();
String data = "some data I want to store on the phone for future use.";
prefsE.putString("NAMETOSAVEDATAUNDER", data);
prefsE.commit();
Get stored data
SharedPreferences prefs = getSharedPreferences("DATA_FILE", 0);
String data = prefs.getString("NAMETOSAVEDATAUNDER", null);
Upvotes: 0
Reputation: 169
I'm not 100% sure if this is what you are asking, but it seems you want to store data in your app to the phone for quick access?
There are a few ways of doing this:
This is more for settings saved in the app in a key value pair style. You can save just about anything, though I wouldn't suggest it for long blocks of text as its main usage seems to be for small variable persistence.
This is good for file storage. Probably a little closer to what you are looking for though it may be a little too intensive for something as storing blocks of text from news articles.
Much the same as internal storage though through the SD card. This is also a file storage system.
This would store all the data to a sqliteDB on the phone. This might be closer to what you are looking for if you have a bunch of articles to store and quickly access. This method might require some more work than the others but will probably be a better method in the long run.
This is what you are doing to pull the data and probably not what you want to use to store it if you want to store it locally, but for others reading this. This would allow you to pull and push data from the net.
Here is a link to all of the Android storage options.
Upvotes: 1
Reputation: 17879
You can use SharedPreferences http://developer.android.com/reference/android/content/SharedPreferences.Editor.html
And make you json object implementing Parcelable
See How to use SharedPreferences in Android to store, fetch and edit values
Upvotes: 0