0

I have my App which downloads & uploads data from/on the server (I have my WebApp written in Java & hence, used SOAP webservice for the communication between my Android App & Java Web App).

Up till now I've been using

AsyncTask

for calling WebServices to download/upload data.

So far so good with small amount of data being downloaded. But when I download the large amount of data from the server the App crashes.

In reference with the android ref doc.

AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and FutureTask.

So I think this is the problem with the AsyncTask being used for longer time interval.

Here is a similar old post

But I am not able to figure it out how to call web services using other threading techniques such as : Thread Pool Executor,Future Task or Executor

Below is my LogCat: enter image description here

Hey, now there is one more problem . I have used IntentService for those long running Network operations (Downloading). Now As My data is big enough while downloading .Hence, in middle of downloading if internet connection is lost then I have to stop the IntentService which I think I can do using.

stopService(new Intent(MainActivity.this, IntentServiceClass .class));

which calls ,

onDestroy()

of the service. But the Code written in ,

onHandleIntent(Intent intent)

will keep on executing. (Which should not happen).

krohit
  • 792
  • 1
  • 7
  • 26

1 Answers1

0

Any long task of this sort should use a android service. The basic problem is the application life-cycle in Android. Any activity and associated threads can be stopped by the operating system. A service by contrast runs background until it suspends or finishes or whatever.

Also good reliable ways to communicate status etc exist to communicate between services and activities.

For details on how to get the service and activity to communicate this question has a lot of very useful information

Community
  • 1
  • 1
Elemental
  • 7,365
  • 2
  • 28
  • 33
  • Yes, I think [Intent Service](http://developer.android.com/training/run-background-service/create-service.html) can be the solution – krohit Aug 07 '14 at 05:00
  • But I have to track the status of the service running i.e. whether it is completed or not(it is required in my case only then I can go to the next activity) & another drawback is you cannot update UI through that. Is there any way to overcome this drawbacks. – krohit Aug 07 '14 at 05:02
  • @RohitKKK edit to add extra link about talking back to your application – Elemental Aug 07 '14 at 07:33
  • I have used the Intent Service but it is giving me error for large download this time it is giving me error : Source Not Found ,android.jar has no source attachment. // Compiled from Throwable.java (version 1.5 : 49.0, super bit) public class java.lang.Throwable implements java.io.Serializable { – krohit Aug 07 '14 at 13:55