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 8435885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:02:27+00:00 2026-06-10T07:02:27+00:00

I have an Activity (RecipiesActivity) that is opened by clicking on the Next button

  • 0

I have an Activity (RecipiesActivity) that is opened by clicking on the “Next” button of the Main Activitiy of my application.

In the RecipiesActivity onCreate, I want to call a webservice in an AsyncTask. For now, since I have not implemented the webservice yet, I am just calling a webservice provided by bitly (but this is irrelevant to my problem).

The problem is that although the webservice gets called and no exception is thrown, a result is return from the doInBackground, but my onPostExecute is not called. I have done some research and I have found the possible reasons as listed below – but none seem to be my case:

  • onPostExecute parameters do not match the AsyncTask parameters – in my case they match
  • A bug in android that does not allow the AsyncTask to be executed in the UI thread. It is supposadely overcomes by using Class.forName(“android.os.AsyncTask”) – I tried this and did not make any difference
  • AsyncTask is not started from the UI thread – in my case I believe it is
  • doInBackground does not return – in my case it does, I have stepped through it with the debugger
  • @Override is not used before onPostExecute – in my case I am using @Override

The code is below:

public class RecipiesActivity extends Activity {

    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_recipies); 
        tv = (TextView) findViewById(R.id.Response);

        //Start the WS call in an AsyncTask 
        new CallWS().doInBackground("https://api-ssl.bitly.com/v3/shorten?login=maskedLogin&apiKey=maskedKey&longUrl=http%3A%2F%2Fgoogle.com%2F");          
    }

    private class CallWS extends AsyncTask<String, Integer, String>
    {
        @Override
        protected String doInBackground(String... params) {

            String result = null;
            HttpClient httpClient = new DefaultHttpClient(); 
            HttpContext localContext = new BasicHttpContext(); 
            HttpGet get_request = new HttpGet(params[0]); 
            try
            {
                HttpResponse httpResponse = httpClient.execute(get_request, localContext);
                //int responseCode = httpResponse.getStatusLine().getStatusCode();
                HttpEntity entity = httpResponse.getEntity();
                if (entity != null)
                {
                    InputStream istream = entity.getContent();
                    BufferedReader br = new BufferedReader(new InputStreamReader(istream));

                    try
                    {
                        result = br.readLine();
                    }
                    catch (Exception e)
                    {
                        //TODO Handle the IOException that the readline may throw 
                    }
                    finally
                    {
                        istream.close();
                    }
                }

            }catch (Exception e)
            {
                //TODO Handle the IOException and the ClientProtocolException that the 
                // httpClient.execute can throw
            }
            finally
            {
                httpClient.getConnectionManager().shutdown();
            }
            return result;
        } 

        @Override
        protected void onPostExecute(String result)
        {
            if (result == null)
            {
                tv.setText("The result is NULL");
            }
            else
            {
                tv.setText(result);
            }
        }       
    }
}

Your help is appreceiated,

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-10T07:02:29+00:00Added an answer on June 10, 2026 at 7:02 am

    Instead of doInBackground(), simply call the execute() method of the AsyncTask. Calling doInBackground() does what it says on the tin: calls doInBackground() (in the same thread) and returns. It won’t call onPostExecute() for you. execute() will start a background thread, call doInBackground() on the background thread, then post the result of doInBackground() to onPostExecute() on the UI thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Activity that should only get created once. That is, onCreate can
I have an Activity whose layout is in the file main.xml that contains a
That's the cuestion , i have: Activity A Activity B From A i want
let's have activity A and button in that activity, which opens activity A again.
I have Activity with ListView inside it and in the onCreate method of the
in my app i have activity with XML layout, i want to build an
I have an activity that when users press share on a file it would
I have an Activity A that calls an Activity B using startActivityForResult() . Under
I have an activity with a spinner which loads a simpleCursorAdaptor. I call another
I have an activity in whose onCreate method an Init function is called (the

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.