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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:05:21+00:00 2026-05-30T22:05:21+00:00

One simple question: is it possible to return a value in AsyncTask ? //AsyncTask

  • 0

One simple question: is it possible to return a value in AsyncTask?

//AsyncTask is a member class
private class MyTask extends AsyncTask<Void, Void, Void>{

    protected Void doInBackground(Void... params) {
         //do stuff
         return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        //do stuff
        //how to return a value to the calling method?
    }
}

And then within my Activity/Fragment:

// The task is started from activity
myTask.execute()
// something like this?
myvalue = myTask.getvalue() 

EDIT:
This was asked a long time ago where I wasn’t familiar with Java, now that I’m better with it, I ‘ll do a quick summary:

The point of async task is that the task is asynchronous, meaning that after you call execute() on the task, the task starts running on a thread of its own. returning a value from asynctask would be pointless because the original calling thread has already carried on doing other stuff (thus the task is asynchronous).

Think of time:
At one point of time, you started a task that will run in parallel with the main thread. When the parallel-running task completed, time has also elapsed on the main thread. The parallel task cannot go back in time to return a value to the main thread.

I was coming from C so I didn’t know much about this. But it seems that lots of people are having the same question so I thought I would clear it up a bit.

  • 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-05-30T22:05:22+00:00Added an answer on May 30, 2026 at 10:05 pm

    Why not call a method that handles the value?

    public class MyClass extends Activity {
    
        private class myTask extends AsyncTask<Void, Void, Void> {
    
            //initiate vars
            public myTask() {
                super();
                //my params here
            }
    
            protected Void doInBackground(Void... params) {
                //do stuff
                return null;
            }
    
            @Override
            protected void onPostExecute(Void result) {
                //do stuff
                myMethod(myValue);
            }
        }
    
        private myHandledValueType myMethod(Value myValue) {
            //handle value 
            return myHandledValueType;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully a simple question although one I have found impossible to answer myself using
Simple question, but one that I've been curious about...is there a functional difference between
Simple question: How do I do this on one line: my $foo = $bar->{baz};
Simple question, but one I can't find an answer to on the MSDN subscriber
I have a simple question related to one-line programming. First an example: function test(a)
Simple question. I'm new to Clojure. How can I use one file from my
Simple question, I think. I have org.springframework.scheduling.quartz.CronTriggerBean triggering one job once a day. Because
My question is essentially a simple one, though I'm looking for as in-depth an
Here's a simple syntax question (I hope), I know how to constrain one generic
This is probably a basic html/css question... I have a simple one-button form that

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.