Android 1.5: Asynctask doInBackground() not called

Put your problem here if it does not fit any of the other categories.

Android 1.5: Asynctask doInBackground() not called

Postby Esc201 » Tue Mar 23, 2010 9:18 pm

Hi all, I am running into an issue with the way my asynctasks are executed. Here's the problem code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. firstTask = new background().new FirstTask(context);
  2.  
  3.     if(firstTask.execute().get().toString().equals("1"))
  4.  
  5.       secondTask = new background().new SecondTask(context);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


What I'm doing here is creating a new asynctask object, assigning it to firstTask and then executing it. I then want to fire off a separate asynctask when the first one is done and making sure it returns a success value (1 in this case). This works perfectly on Android 2.0 and up. However, I am testing with Android 1.5 and problems start popping up. The code above will run the first asynctask but doInBackground() is never called despite onPreExecute() being called. If I am to execute the first task without the get() method, doInBackground() is called and everything works as expected. Except now I do not have a way to determine if the first task completed successfully so that I can tell the second task to execute. Is it safe to assume that this is a bug with asynctask on Android 1.5? Especially since the API (http://developer.android.com/intl/de/re ... #get%28%29) says that the get method has been implemented since API 3. Is there any way to fix this? Or another way to determine that the first task has finished?
Esc201
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Mar 23, 2010 9:00 pm

Top

Re: Android 1.5: Asynctask doInBackground() not called

Postby Boni2k » Fri Mar 26, 2010 9:50 am

Esc201 wrote:Or another way to determine that the first task has finished?

Not sure if you mean that but wouldn't

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. doInBackground(...) {
  2.  
  3. ...
  4.  
  5. }
  6.  
  7.  
  8.  
  9. onPostExecute(Object result) {
  10.  
  11.     new SecondTask().execute("");
  12.  
  13. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


in your first task work for you?
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 26 guests