Currently I use an Activity to upload an image to the web, I'm using AsyncTask and everything is working great. I currently use an Activity to achieve this, basically the activity allows the user to enter a few details, take a picture and then submit, a progress dialog is displayed until a response is received. When on E or G connections the whole process can be quite lengthy (in excess of a minute). Its not possible to finish the activity and return to the previous activity (which is what I want) until a response is received.
What options do I have. Currently if I press the home button the process works fine and continues to upload, can the application be minimized programmability? . I see many problems with this approach, for example if the activity closes or an error occurs.
The only approach I can think of is to move the actual upload code to a service, gather the information using the activity and allow the activity to start a new service for each upload? I can then notify the user of success or failure using the NotificationManager and handle the re-try in the service.
I noticed that when sharing an image from the gallery to Facebook the activity immediately closes and the user receives feedback via a notification. I'm assuming this approach uses a service to upload the image to Facebook?
Any help / advice would be much appreciated.
Regards
I suggest you to use the following setup:
Using a service instead of an Activity has some advantages. For example, you don't have to worry with configuration changes (like changing the orientation of the device), you don't "lock" the user in an activity where they have nothing to do, etc.
Uploading doesn't require a UI so using an activity isn't the best way to do it.
In short: use a service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With