File upload in background: thread/service/AIDL...?

by Mark Murphy » Tue, 02 Mar 2010 01:31:53 GMT


Sponsored Links
 


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!

--



Other Threads

1. How to make surfaceview insensitive to touch Events

Hi,

When i am running mediaplayer, i want the surfaceview to be
insensitive to motion events. I tried
mSurfaceView.setFocusableInTouchMode(false); but its not working..
please guide me in this..

Thanks
Nithin
--~--~---------~--~----~------------~-------~--~----~

2. HttpClient4 execute(HttpPostMethod) failed

Greeting...

I am using android sdk1.0 release2 on windows XP to test
httpclient.execute(httppostmethod), but failed.
The compute connects to Internet w/o any problem.

Here is releated code
....
DefaultHttpClient client=new DefaultHttpClient()
try{
HttpPost method=new HttpPost("http://www.xyz.com") ;// a real website.
List<NameValuePair> data=new ArrayList<NameValuePair>;
data.add(new BasicNameValuepair("name1", "astring");

method.setEntity(new UrlEncodedFormEntity(data));
Log.i("test", "==1==");
HttpResponse response=client.execute(method);
Log.i("test", "==2==");

......
} catch(IOException e){
.....
}
.....

The code is compiled correctly, but failed at run.
it failed at the line: HttpResponse response=client.execute(method);
because I can see log: ==1==, not ==2==.
the error in log is: E/OSNetworkSystem(300): unknown socket error -1.

PS: when I run androidm5-r14 with httpclient3.x, it works fine with
aother window XP laptop on the same network. I do not think different
laptop with same window XP platform will make the difference. at
least, it should not.

Does android 1.o r2 has anyproblem running httpclient4 execute
httpost?

Thank you for any help or info.

Thank you!

Best Regards,

ever

--~--~---------~--~----~------------~-------~--~----~

3. Fwd: Questions to enhance/replace Android GNU tool chains

4. Audio Volume

5. How to record audio stream?

6. Micro Thumbnail Issue

7. Where are all the Android sessions at SD West?