Following http://ift.tt/1P91B1d I created an app that loads a data and puts it to internal SQLite DB.
The problem now is that data loading is the first thing application must perform and only after each data entity is successfully loaded to DB, it can show user the first page.
It's calling web API for the information using:
gsonGetRequestItems = ApiRequest.getItems
(new Response.Listener<Items>() {
@Override
public void onResponse(Items dummyObject) {
}
}
,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
gsonGetRequestOtherItems = ApiRequest.getOtherItems
(new Response.Listener<OtherItems>() {
@Override
public void onResponse(OtherItems dummyObject) {
}
}
,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
App.addRequest(gsonGetRequestItems, "jsonProd");
App.addRequest(gsonGetRequestOtherItems, "jsonProd");
There are 6 requests like that. Inside each one the app deserializes received jsons and inserts data to DB row by row.
The calls are asynchronous, that contradicts to the requirement that everything should be fully and successfully loaded to DB before continuing any further user flows.
How do I make the code to listen for each success / error call and execute startApplication(); for homepage loading depending on that it received 6 successful DB update call states?
If some of them ended with error, I'll restart everything.
Aucun commentaire:
Enregistrer un commentaire