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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:32:10+00:00 2026-05-22T12:32:10+00:00

friends, i am running async task from application onCreate() now i want to raise

  • 0

friends,

i am running async task from application onCreate()

now i want to raise an interface on completion of this task and implement it in ACtivity B.

any one guide me how to achieve this?

my Interface

public interface IBanksLoader 
{
    public void OnBankLoadingComplete(boolean complete);
}

in application class

AsyncTask
{

any other function();
// to raise it here
}


Activity b
{

// implement it here to get result.
}

any help would be appreciated.

  • 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-22T12:32:11+00:00Added an answer on May 22, 2026 at 12:32 pm

    You can use the observer pattern to implement this behavior.

    Activity B would implement the IBanksLoader (observer) interface and register itself to some central component. This central component must get notified when the AsyncTask finished and calls then OnBankLoadingComplete() (is equivalent to notify() of the Observer interface) of all registered observers.

    I would suggest to use a Singleton or an Application class as central component as they can be accessed easily form anywhere within your application, also from the AsyncTask.

    But be aware of your application’s life cycle. So your might need to unregister Activity B at some time, e.g. before it gets destroyed. Otherwise the central component would call OnBankLoadingComplete() on an object which is null and thus raise a NullPointerException.

    UPDATE

    public class ActivityB extends Activity implements IBanksLoader {
    
        public void onCreate(){           
            ...
    
            MyApplication app = (MyApplication) getApplication();
            app.register(this);
    
            ...
        }
    
        public void OnBankLoadingComplete(boolean complete){
    
             // your code here ...
        }
    
        public void onDestroy(){
            MyApplication app = (MyApplication) getApplication();
            app.unregister(this);
        }
    }
    
    
    public class MyApplication extends Application{
    
        private List<IBanksLoader> observers = new ArrayList<IBanksLoader>();
    
        public void register(IBanksLoader observer){
            if(observer != null){
                oberservers.add(observer);
            }
        }
    
        public void unregister(IBanksLoader observer){
            if(observer != null){
                oberservers.remove(observer);
            }
        }
    
        public void taskfinished(){
            foreach(IBanksLoader bank : observers){
                if(bank != null){
                    bank.OnBankLoadingComplete(true);
                }
            }
        }
    }
    
    
    public class MyTask extends AsyncTask{
        ... 
    
        public void onPostExecute(){
            MyApplication app = (MyApplication) getApplication();
            app.taskfinished();
        }
        ...    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to post something in the users friends wall. I use this to
I wrote a script to export twitter friends as foaf rdf description. Now I'm
I have a database table that i want to allow my friends to update.
Hello friends i am running code given below which contains the setLogTimeEntery function and
friends, I'm running into an issue when i try to call webservice and the
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when
I have a PHP application running in iFrame mode. I am rendering an <fb:multi-friend-selector
Some friends and colleagues of mine have a little running contest to find or
well I have this script and basically it's doing a loop of stuff, now
Hello friends I am running 2 applications on the same server and I wanted

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.