I've built an application which uses an IntentService for manipulating the application's database and calling web services.
Example:
I have an Activity which is a list of items. This list is populated by a CursorAdapter. Each item has a checkbox and the list is ordered by checked (unchecked items on top and checked items on bottom). When an item's checkbox is checked, I send an Intent to my IntentService telling it to flag the checked column in the database table for that item, then a message is Broadcasted, the Activity sees it and re-queries the Cursor.
When I'm using a mobile device and start rapidly checking checkboxes, the app essentially hangs. The UI doesn't hang, but the IntentService in the background does. I can tell because the Cursor on screen isn't getting refreshed.
It is my understanding that Intents passed to IntentServices are not processed asynchronously. Is that correct? It's behaving almost like I need to be using semaphores, but I can't understand why if Intents are queued and processed individually.
Suppose I check 3 checkboxes; so there are 3 Intents queued. After the first one I broadcast a message, which the Activity receives, telling it to requery it's cursor. Could a potential problem be because I'm requerying the Cursor at the same time I'm processing the second Intent (updating another row in the table)? Querying the Cursor happens on the UI thread.
^ I think this is my problem. What should I use to synchronize this? Semaphores? Can someone point me to some documentation/examples?
Another potential issue is what if my Activity manages a Cursor on a table; also my IntentService queries a Cursor from the same table. I have instances where this happens as my IntentService is going through each row in the Cursor to find items to send to the web service. Though I wouldn't think this would be a problem so long as the Cursors don't query at the same time?
Does anyone have any other ideas?