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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:03:34+00:00 2026-06-01T06:03:34+00:00

I have the following asynctask class which is not inside the activity. In the

  • 0

I have the following asynctask class which is not inside the activity. In the activity I’m initializing the asynctask, and I want the asynctask to report callbacks back to my activity.
Is it possible? Or does the asynctask must be in the same class file as the activity?

protected void onProgressUpdate(Integer... values) 
{
    super.onProgressUpdate(values);
    caller.sometextfield.setText("bla");
}

Something like this?

  • 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-01T06:03:35+00:00Added an answer on June 1, 2026 at 6:03 am

    You can create an interface, pass it to AsyncTask (in constructor), and then call method in onPostExecute()

    For example:

    Your interface:

    public interface OnTaskCompleted{
        void onTaskCompleted();
    }
    

    Your Activity:

    public class YourActivity implements OnTaskCompleted{
        // your Activity
    }
    

    And your AsyncTask:

    public class YourTask extends AsyncTask<Object,Object,Object>{ //change Object to required type
        private OnTaskCompleted listener;
    
        public YourTask(OnTaskCompleted listener){
            this.listener=listener;
        }
    
        // required methods
    
        protected void onPostExecute(Object o){
            // your stuff
            listener.onTaskCompleted();
        }
    }
    

    EDIT

    Since this answer got quite popular, I want to add some things.

    If you’re a new to Android development, AsyncTask is a fast way to make things work without blocking UI thread. It does solves some problems indeed, there is nothing wrong with how the class works itself. However, it brings some implications, such as:

    • Possibility of memory leaks. If you keep reference to your Activity, it will stay in memory even after user left the screen (or rotated the device).
    • AsyncTask is not delivering result to Activity if Activity was already destroyed. You have to add extra code to manage all this stuff or do you operations twice.
    • Convoluted code which does everything in Activity

    When you feel that you matured enough to move on with Android, take a look at this article which, I think, is a better way to go for developing your Android apps with asynchronous operations.

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

Sidebar

Related Questions

I have the following code: public class TestSynch extends Activity { public static ArrayList<HashMap<String,String>>
I have an AsyncTask which calls my LocationHandler class method getLocation() which runs a
I have the following code which does nothing but reading some values from a
friends, i am using following code inside asyncTask public class AsycLoaderFromDbAndMapInjector extends AsyncTask {
I have the following code class OverlayTask extends AsyncTask<Void, Void, Void> { @Override public
Possible Duplicate: nullPointerException in multi column list I have following app which fetches data
I have following div in a page (I can not modify). <div id=:0.control>Click me</div>
I am trying to execute the following AsyncTask : private class TimeUpdateTask extends AsyncTask<List<mObject>,
I currently have a helper class to perform rudimentary AsyncTasks such as the following.
I have the following code that downloads a video using AsyncTask. //DOWNLOAD VIDEOS private

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.