How to Define Callbacks in Android? -


During the most recent Google IO, there was a presentation about the implementation of cool client applications. Unfortunately, this only There was not a high level discussion with the source code of implementation.

In this diagram, there are different callbacks on the return path in other ways.

How do I declare these methods?

I understand the idea of ​​callback - a piece of code is said after a certain event, but I do not know how to implement it. The only way I have implemented callback so far, override various methods (for example on OnActivityResult).

I think I have a basic understanding of the design pattern, but how am I going to handle the return path?

In many cases, you have the interface and passes it with the object. For example on DialClickListener is on the dialog.

Just as a random example:

  // Callback interface interface MyCallback {void callbackCall (); } // class callback class worker {MyCallback callback; Void onEvent () {callback.callbackCall (); }} // Option 1: class callback implies MyCallback {void callbackCall () {// callback code goes here}} worker.callback = new callback (); // Option 2: worker.callback = New MyCallback () {void callbackCall () {// callback code goes here}};  

I probably messed up the syntax in Option 2. It's elementary.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -