Anna PS wrote: > Nothing, really. I just want to upload a file in the background, with > an icon in the status bar, and update the icon when the upload is > complete. > > I might possibly want to call the main application back again when the > upload is complete or if there is a problem, but I don't expect to use > the Service for anything else. > > Does that sound OK? So the most communication I would need is (i) pass > a filename to the Service, and (ii) go back to the main application > once the upload is complete.
In which case, do the following: Step #1: Implement your Service as a subclass of IntentService. IntentService handles the whole background thread thing for you, so you will not need an AsyncTask. Step #2: Put your file-upload logic in onHandleIntent() in your IntentService subclass. Step #3: When you have something to upload, create an Intent that identifies the service (e.g., new Intent(this, MyService.class);) and put a string extra on it (via putExtra()) that contains the thing to upload. Step #4: Call startService() with the Intent from Step #3. Step #5: In onHandleIntent(), you are passed the Intent, so you can call getStringExtra() to get the value and use it. Step #6: There is no step #6. Your service will automatically shut down when there is nothing more to upload, and it will be restarted automatically if another upload is required. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 2.0 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en