Reputation: 97
In my main activity i am sending a HTTP GET request (with user GPS location and a range) to server by clicking on a button and get server response as JSON with a list of places around the position of the client and inside the range specified in the request.
I want to wait for this response to do some other stuff on this list. I am using a AsyncTask.
Since this task is the main purpose of the application and it can be repeated multiple times, to avoid the request for the list every time the user click on the button. I want to reuse the list.
To reuse the list the more possible number of times. I can ask the server a list with a bigger range. But the more the range is higher the more the response is slower.
So I think that I should ask this bigger list in background by using an IntentService, is it right?
How can I save the results of the IntentService without using a local DB(I don't need to refresh the UI)? (so that I can check if a bigger list exists, if it's valid (w.r.t. user current location) and use it) Is it possible to share this list in different activity (without passing with Intents)?
Upvotes: 0
Views: 458
Reputation: 1558
Here is piece of code
String jsonData="your json data you wanna save";
SharedPreferences sharedpreferences=getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE);
//save your incoming json
Editor editor = sharedpreferences.edit();
editor.putString("mydata",jsonData); editor.commit();
//Access your saved json from anywhere or from other activities
String myDataBack=sharedpreferences.getString("mydata","");
//compare your data
Upvotes: 2