0

I am currently building a library where it would be useful to allow people using it to specify a section of their own code to run in the middle of the library functionality.

For example much like an async task does with its onPreExecute etc methods or how an on event listener does.

However I have no idea how to go about creating this and the correct keywords that would point me towards answers are eluding me from my searches.

Specifically I would like to implement something like:

LoadingKit.performSomeCode (new thing () {

       \\code goes here

}).otherImportantMethods ();

Apologies for the vagueness and any help would be great.

1 Answer 1

1

You create an interface with the methods you wish them to implement. Then you have them pass you an instance of that interface. When you wish to call them, you call that interface. Like this

public interface MyFoo {
    void run();
}

public void setMyFoo(MyFoo foo) {
   mMyFoo = foo;
}

//time to call their code
mMyFoo.run();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.