Ad
Best Approach To Get Data From Server And Save It To In Local DB?
I am downloading data from server and storing it in local sqlite db.i want know which is the best approach to do this so that my app ui thread will not get freeze. Currently i m using volley and app gets freeze sometime and i get log too "skip frames". Thanks.
Ad
Answer
In Volley, onResponse and onErrorResponse is called on UI thread. So please move you parsing logic into parseNetworkResponse (as this is done in background thread) or you can use Executors (or ExecutorServices depending on your use case) or AsyncTask to switch the threads once you receive the response in OnResponse and save the data in the local DB like shown below.
public void onResponse(JSONObject response) {
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(() ->
// your database code
);
}
or
public void onResponse(JSONObject response) {
AsyncTask.execute(new Runnable() {
public void run() {
// your database code
}
});
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad