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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:05:31+00:00 2026-06-17T16:05:31+00:00

I am developing an app where in a number of the activities I need

  • 0

I am developing an app where in a number of the activities I need to retrieve data via Http.
Once I have the data I process it in the onPostExecute() callback method.

This works fine if I define the async task as an inline class, but as I want to do the same processing in a number of activities I have defined it as an external class.

So the question is, using an external class how do I signal an “event” back to the calling class as a means of passing the data back. I know how to do this in C# but I am new to Java and can not see how to achieve 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-17T16:05:32+00:00Added an answer on June 17, 2026 at 4:05 pm

    While it is true that a Listener technically correct, I would claim that it is either too complicated or not complicated enough.

    Here’s an easier solution:

    class Foo {
       class Bar extends AsyncTask<Void, Void, Result> {
    
          public void onPostExecute(Result res) {
             doSomething(res);
          }
       }
    
       public void doSomething(Result res) {
          /// process result
       }
    
       public void startTask() {
           new Bar().execute();
       }
    }
    

    Is equivalent to:

    class Bar extends AsyncTask<Void, Void, Result> {
         private final Foo foo;
         public Bar(Foo foo) { this.foo = foo; }
    
         public void onPostExecute(Result res) {
           foo.doSomething(res);
         }
    }
    
    
    class Foo {
       public void doSomething(Result res) {
          /// process result
       }
    
       public void startTask() {
           new Bar(this).execute();
       }
    }
    

    … which is what you asked: when you pull the inner class out, you lose the implicit pointer. Just make it explicit and pass it in.

    The bad news is that there are all sorts of memory leak and lifecycle issues that arise from this solution. I would very much recommend that, before your program gets even bigger, you looking into using an IntentService instead of an AsyncTask and use a Handler, or Activity.runOnUiThread to get the results back onto 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 been developing an iPhone app which queries a server that relays data
I have been developing a number of Android activities in a project in Eclipse.
I am developing an app that needs to refer to data in a number
I'm developing a housing app with a number of houses which each have attributes.
i am developing an app in that i just need IMIE number of device...
I'm developing an app that uses Core Data for save and retrieve data. Now
I am developing an app, which display number of books fetched from the server
I am developing an iPad app that has a large number of UIViewControllers ,
I am developing an Android application. This app deals with contact information (name, number,
I am developing an app where I need to show a count. This count

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.