tags:

views:

108

answers:

1

I'm designing an android app which will need to do the following steps:

  1. user pushes a button or otherwise indicates to "synch data".
  2. synch process will use REST web services to move data to and from the server.
  3. the data will be stored locally in a sqlite database.
  4. the synch process should provide status updates/messages to the UI
  5. the user should not be allowed to wander off to other parts of the application and do more work during the synch process.

The first time the synch process runs, it may take 10-20 minutes. After the initial synch, less data will be transferred and stored and I expect the process to take 1-2 minutes or less.

I've been doing a lot of reading about android's AsychTask and various examples of using a Service ... But I don't fully understand the design considerations and trade-offs of choosing one design over the other. I currently have my demo project stubbed out using an AsychTask. After watching (most of) Developing Android REST client applications: http://code.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html# I'm left confused the design patterns described here feel overly complex, perhaps because I just "don't get it" yet.

I come from a java, spring, web and desktop application background. Thinking and designing in terms of a handheld device is quite new to me. (What happens when the screen layout is changed? What happens when the phone rings while I'm running a synch?) Taking 2 steps back, if the initial synch IS going to be such a long running process, is there a better way for me to think about the problem->solution, the user experience, the user expectations of an application running on a phone?

Would love to hear from some more experienced android developers out there who have already wrestled with these questions.

A: 

With AsyncTask if the user goes to another Activity you can't transfer that object to the other Activity so it dies. There are tricks you can play when say the user rotates the screen or something like that, but that doesn't extend to general purpose destruction. AsyncTask can randomly die.

Google Sync is run as a Service in the background because syncing can take a while to complete. You might need to follow their path and create your own sync service that you can communicate with. Here is some thoughts how to accomplish that:

http://mylifewithandroid.blogspot.com/2008/01/about-binders.html

You can definitely communicate between Service and Activity, but it's tricky to do it right.

chubbard