1

I have an application which has some background processes, like downloading an XML from a server and parsing it, and I am performing these tasks in Threads.

The problem comes when sometimes a thread does not get CPU time for long time, it could be anytime between 15 minutes to some hours, and then the thread starts behaving properly.

How should I handle this?

DMA57361
  • 3,600
  • 3
  • 27
  • 36
Karan
  • 497
  • 10
  • 23
  • normally i would say use an asynctask but your saying it could take 15 minutes + to fetch xml ?? What exactly will take 15+ mins, is it the downloading of the XML or is it some sort of long running process. 15+ mins is a long time .. – Marty Jul 20 '11 at 12:45

3 Answers3

3

use the AsyncTask class for this.

in this you can perform to fetching or processing in background and until the background process was not complete the another method of this class was not execute

check this links for tutorial and guidlines

http://www.vogella.de/articles/AndroidPerformance/article.html

http://developer.android.com/reference/android/os/AsyncTask.html

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • i have used Async task but my question is that i m downloading a file in thread continuously after 15 mins. But as we know processor using some scheduling processes each thread one by one. So sometimes on losing CPU Time My application threads are not getting CPU Time for a long while. Plz tell me how can get back CPU attention. – Karan Jul 20 '11 at 13:39
1

Use AsyncTask Class For Parsing XML From Server

Mohit Verma
  • 3,025
  • 1
  • 20
  • 36
0

My experience with AsyncTask is not very good, and it will terrible with very long operations like 15 min (you will have problems such as UI interaction, limits, etc.)

I recommend you create a service instead (IntentService is easy to work with) that will broadcast it reult when it is finished.

Community
  • 1
  • 1
rds
  • 26,253
  • 19
  • 107
  • 134