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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:17:14+00:00 2026-06-07T10:17:14+00:00

I’m having a go at extending Activity to define a standard method I can

  • 0

I’m having a go at extending Activity to define a standard method I can callback to from an AsynchTask. Here’s a skeleton code.

public class R3Activity extends Activity{


    public void displayresult(String xmlresult){

    }//displayresult


}

Now any activities I create by extending R3Activity can implement a displayresult method.

I then use this as follows…..

    public class MainActivity extends R3Activity{


    private void somemethod(){
           DatabaseAccess dba = new DatabaseAccess();
           dba.setActivity(this); // Pass a ref to the activity into the class with the Asynch task
           dba.execute(new URL(database_url));

    }

    }

}

The DatabaseAccess class is supposed to be a generic class that goes off and fetches data using an AsnchTask. My problem is handling the callback in a generic way.

public class DatabaseAccess extends AsyncTask<URL, String, String> {
        private R3Activity m_activity;

    public void setActivity(R3Activity activity) {
        m_activity = activity;
    }

    @Override
    protected String doInBackground(URL... params) {
           //Connect to database etc
           String strdata = "blah";

        }

    protected void onPostExecute(String result) {
        if ((strdata != null) && (m_activity != null)) {

            m_activity.displayresult(strdata);

        }
    }

}

Now m_activity.displayresult works because this method is available in every instance of an R3Activity.

How do I get displayresult() to trigger an Event handler that I can implement in every Activity.

Something like….

public class MainActivity extends R3Activity implements  DatabaseResultListener {


public void DbCallback(){
//This gets triggerred by the displayresult callback
}

}
  • 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-07T10:17:15+00:00Added an answer on June 7, 2026 at 10:17 am

    I think you should use interface for callback.and you can do it easily.

    interface AsyncTaskListener{
         public void onTaskComplete(T result)
    }
    

    Then implements it

    public class MainActivity extends Activity implements AsyncTaskListener
    

    And in AsycTask,onPostExecute method call listener method like,

     objAsyncTaskListener.onTaskComplete(T result);
    
    • See here
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.