Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneral application design (IntentService/ContentProvider/AsyncTask)
    primarykey
    data
    text
    <p>I'm trying to figure out what is the best general design for applications that access several web services and have multiple activities where information is displayed.</p> <p>The way I implemented my latest Android application is the following. I have an <code>IntentService</code> that receives requests from activities to get information from web services. My <code>Service</code> notifies the activities through a <code>ResultReceiver</code> about the status of the request (started/error/finished). After calling the web service, getting the result(xml/json) and parsing it, I put that information in a <code>ContentProvider</code> (backed up by a sqlite database) and use a <code>ContentResolver</code> to notify any activities about the changes. The activities get notified about the changes (some use <code>ContentObserver</code> and others use <code>SimpleCursorAdapter</code>s and are notified automatically).</p> <p>Now, the problems with my approach:</p> <ul> <li>every time I enter an activity, I request info from web service through the method described above and I delete all the rows in that particular table, fill it with the new info and notify the activity. So, if the user presses back and then enters again, I do the whole dance again. I think I should add some fields in the database for when was the last updated etc. but I don't know how exactly to proceed with that. Suggestions? I think one alternative would be to use alarms and trigger updates at specific intervals. But in my case, the specification asks to check the web service every time I enter the activity.</li> <li>when I call the web service, I show a indeterminate progress bar in the activity, over the other views (which contain the info fetched previously and that sits in the database until the web service call finishes) but the user can start interacting with the views and this is not good (the info may disappear from the database). Any way to disable the interaction? A ProgressDialog comes to mind.</li> <li>if I move quickly through different activities, the IntentService is blocked with previous web service calls and it takes longer to get to my latest web service call. I could create multiple <code>IntentService</code> for every web service but I don't think this is its purpose.</li> </ul> <p>I have the feeling that the approach I have taken is not really the best one for this particular application. It is <em>partially</em> inspired from the Google I/O application (I couldn't understand everything, like the updated sqlite fields etc.). One alternative would have been to use AsyncTasks in all the activities. But where can I store the info in order to be accessed from other activities? In lists in <code>Application</code>? And how about id management?</p> <p>I'm really interested on your opinions/ideas/suggestions and how can I make my next applications work better and more efficiently.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload