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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:35:33+00:00 2026-06-05T19:35:33+00:00

I have a remote call that I make and I am wondering where it

  • 0

I have a remote call that I make and I am wondering where it is better to put this processing code:

        if ( result == null )
        {       
            Toast.makeText(getApplicationContext(), "Some error message", Toast.LENGTH_LONG).show();                                

        }
        else
        if ( result.equals( "all_problems_db_error" ))
        {
        Log.d( "AllBusinessesActivity" , "result: " + result )                                      
        }
        else
        {
            // Unwrap the stuff from the JSON string                
            String problem_title = null;
            String problem_id = null;

            try
            {
                JSONArray obj = new JSONArray(result);

                if ( obj != null )
                {
                    problems.clear();

                    for ( int i = 0; i < obj.length(); i++ )
                    {
                        JSONObject o = obj.getJSONObject(i);

                        problem_title = o.getString("problem_title");
                        problem_id = o.getString("problem_id");

                        Problem p = new Problem ( );
                        p.setProblemId(problem_id);                         
                        p.setProblemName(problem_title);

                        problems.add( p );
                    }

                    adapter.notifyDataSetChanged();             

                }                                   
            }
            catch ( Exception e )
            {
           // Do something :)
            }               
        }

Is it better to have it in the onPostExecute() or at the end or doInBackground() ?

I now do it in onPostExecute() but every once in a while I experience some slowness, and I have been reading that it might be better to do this in the doInBackground.

Could someone please explain to me the difference? And if I do this in the doInBackground() then what is the purpose of having the onPostExecute method?

  • 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-05T19:35:34+00:00Added an answer on June 5, 2026 at 7:35 pm

    Is it better to have it in the onPostExecute()

    Since in your case there is no manipulation of any UI component, you can have the code in doInBackground(). But since you are showing a toast when the result is null you can check the result in doInBackground() and if the result is not null you can do the remaining processing on that result in the same function or else you can pass on to onPostExecute() where you can show the toast.

    at the end or doInBackground()
    Yes. You can have this code at the end of doInBackground() since this method runs on a non-UI thread and this will definitely reduce the slowness you experience.

    The difference between both these method doInBackground() and onPostExecute() is simply that the former runs on a non-UI thread and the later on the UI-Thread.

    And if I do this in the doInBackground() then what is the purpose of having the onPostExecute method

    Usually the doInBackground() is used to perform time consuming operations. These operations may include activities like calling a webservice or fetching images from servers. In such cases (like fetching images from servers) you want that images to be displayed on your screen (which is your UI). After you fetch these resource you pass on the data to the onPostExecute() where you can update your UI since it runs on your UI thread.

    Hope this explanation clears your doubt.

    • 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 makes a remote server call and tries to populate
I have set up the code to call a remote server from Android app
I have an ActiveRecord Model, PricePackage. That has a before_create call back. This call
I know the app servers like Websphere and Weblogic have remote deployment capabilities that
I have a remote SVN repository that I connect to via HTTPS. The repository
I've got an object that encapsulates remote calls. It needs credentials to make the
I have a segue that I do like this: [self performSegueWithIdentifier:@PlanToBusiness sender:self]; it works
I have a Java program that runs on Linux and telnets into a remote
I have a script that retrieves objects from a remote server through an Ajax
Currently I have a website on my local computer that uses PHP to make

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.