Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:20:51+00:00 2026-06-09T18:20:51+00:00

Strangley, my AsyncTask will execute onPreExecute but not doInBackground() or onPostExecute() . Logcat has

  • 0

Strangley, my AsyncTask will execute onPreExecute but not doInBackground() or onPostExecute().
Logcat has no error or message indicating that something is going wrong.

class LocationTask extends AsyncTask<String, Void, String>{

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.d(TAG, "onPreExecute============");
    }

    @Override
    protected String doInBackground(String... urls) {
        Log.d(TAG, "doInBackground============");
        Log.d(TAG, "urls[0]:" + urls[0]);
        return "test";
    }

    @Override
    protected void onPostExecute(String result){
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        Log.d(TAG, "onPostExecute============");
    }
}

public class CsLocationTaskTest extends AndroidTestCase {

    public void testExecute(){
        LocationTask task = new LocationTask();
        task.execute("my_test_url", null);
    }
}

As you see, AsycTask is nothing special, but doInBackground and onPostExecute are not being called in both a test case and in my Activity. I don’t understand what happened, please let me understand what is wrong. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:20:53+00:00Added an answer on June 9, 2026 at 6:20 pm

    AsyncTask needs to be a sub class of CsLocationTaskTest. Also, you don’t need null.

    Per the development document:

    "AsyncTask must be subclassed to be used. The subclass will override at least one method (doInBackground(Params...)), and most often will override a second one (onPostExecute(Result).)"

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

    Try this:

     public class CsLocationTaskTest extends AndroidTestCase {
    
        public void testExecute(){
            LocationTask task = new LocationTask();
            task.execute("my_test_url");
        }
    
        class LocationTask extends AsyncTask<String, Void, String>{
    
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            Log.d(TAG, "onPreExecute============");
        }
    
        @Override
        protected String doInBackground(String... urls) {
            Log.d(TAG, "doInBackground============");
            Log.d(TAG, "urls[0]:" + urls[0]);
            return "test";
        }
    
        @Override
        protected void onPostExecute(String result){
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Log.d(TAG, "onPostExecute============");
        }
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

fairly new Android developer here. I've come across a strange problem that I'm not
I am having a strange error that seems to occur only in Samsung Galaxy
Strangely I noticed that the model previous method is not working the way I
I thought QHostAddress was it, but it strangely does not provide methods for validating
I read many question about that and tutorials, but the only one executed, and
Strangely I had this working before but I reinstalled my system, upgraded to w7
Strangely I find no support for Midi in Android. The only thing that comes
The question is worded a bit strangely, but I couldn't figure out any other
I found a php function checkdate() , but strangely enough it only seems to
We've got an Eclipse RAP application that's behaving a bit strangely in Firefox -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.