Question

My app makes several calls to getFromLocationName from the android.location.Geocoder; class, this is currently handled in my activity which also displays some data depedant on the results of that call.

This can be quite slow, for example before the activity can load it first has to complete the various calls, and that is reliant on a network connection.

Once I have the results, I don't really need to refresh that (I mean how often do locations and geo coordinates change?)

My question : How can I best avoid having to query for this data each time my app runs. Should I do something with a service that loads them all on startup? (could be quite slow if it has to query 50+ times). OR should I make the call, store results in SQL, then only query next time if I don't currently hold the results?

Was it helpful?

Solution

If you want to quickly cache it, I would recommend storing the most recent results in a SQLite database. You could probably even get away with using the PreferenceManager for quick storage if you don't need the database for anything else. Just store the latest co-ordinates and the datetime, then check to see if the datetime has expired after X minutes or X hours (if that's what you're wanting to do).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top