Caching Google Places API data locally on Android device for history feature
I am developing an Android app using Google Places API and would like to implement a search history ListView activity for the place details activities visited by the user. So then the user can come in to this page and view the search history in here without the need for performing another search. This will increase the user experience and also reduce the number of API calls made back to Google Places database.
I am only going to show the place name and address and nothing else.
So I did some research and found that this can be achieved by caching the data and retrieving back on activity using the below methods:
Shared Preferences
Internal Storage
SQLite Databases
Out of the above options shared preferences seems to be one for settings and preferences activity and the last 2 could work for my requirement.
1st Question: Am I allowed to cache Google Places API data locally on the device and retrieve them back to display on the history activity? My App does not have a database so local device storage would be the only option.Also I checked the below links and they say I can cache or store the place_id and not other contents outside the service. That means I can cache the place name and address within the app or on internal device storage? If I can only store place_id then do I have to make individual API calls to retrieve place name and address every time the user visits the history activity? What if the user has 50 listings?
https://developers.google.com/places/web-service/policies#pre-fetching_caching_or_storage_of_content
https://developers.google.com/maps/terms#section_10_5
2nd Question: If I am allowed then which one to use to store and load n number of data as history would be go lot until user clears them periodically.
Please help?
I would suggest you to use SharedPreferences
, for any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to storage. Objects that are returned from the various get methods must be treated as immutable by the application. Interface for accessing and modifying preference data returned by getSharedPreferences(String, int)
To store values in shared preferences:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Name","Harneet");
editor.apply();
To retrieve values from shared preferences:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String name = preferences.getString("Name", "");
if(!name.equalsIgnoreCase(""))
{
name = name + " Sethi"; /* Edit the value here*/
}
链接地址: http://www.djcxy.com/p/63170.html