heavy operation in Service Async Task freezes the screen

I've developed an application and one of its aims is to upload a file to the server. On average the file is quite large and upload takes a lot of time, so to make sure it'll be processed till the end, I moved the critical part of IO to the IntentService. From the IntentService for every single upload there's an AsyncTask started which does the IO job. Unfortunately the screen scrolling gets freezed several times while doing the upload in the background. I thought that a combination of IntentService+AsyncTask should be enough... I'd be grateful for any suggestions how to solve it..

Answers


I think you may be misusing IntentService. I am assuming that you are calling AsyncTask.execute(...) from IntentService.onHandleIntent(Intent).

IntentService was created to perform background tasks one at a time on a non-UI thread. This means that onHandleIntent(Intent) is invoked from a background thread and should not be creating AsyncTasks. Furthermore, once onHandleIntent(Intent) finishes (and it does so immediately if all you do is start an AsyncTask) the service is a candidate for being shut down.

I know that this doesn't directly answer your questions but it may point to the causes of the issue. Note that if you need to be able to handle multiple requests concurrently then your best bet is just to extend Service and enqueue a work request onto an Executor in onStartCommand(...).

[EDIT] For more information on proper usage of IntentService check this out.


Need Your Help

Javascript templates

javascript templates genshi

Does anyone know if is there any way to create javascrit templates in Genshi? I mean, I need a .js file where I can use directives like <py:for> and so.

html emails - problem with <button> inside <a> tags?

html html-email

The following looks fine but when i test it in gmail, it opens the link twice (in 2 new tabs), it's as if there's some kind of wierd event bubbling happening....