Created
August 6, 2019 21:56
-
-
Save blundell/902d7283489a5eb2edda7823d4a38b05 to your computer and use it in GitHub Desktop.
Listener Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HellowWorldRepository { | |
interface Listener { | |
void onSomethingDone(String result); | |
} | |
public void doSomething(Listener listener) { | |
new Thread(new Runnable(){ // this is the worst way to do threading, google "android threading" | |
@Override | |
public void run() { | |
// do some stuff | |
listener.onSomethingDone("Hello World"); | |
} | |
}).start(); | |
} | |
} | |
class OtherClass { | |
public void something() { | |
HellowWorldRepository repo = new HellowWorldRepository(); | |
repo.doSomething(new Listener() { | |
@Override | |
public void onSomethingDone(String result) { | |
Log.d("TUT", "Success " + result); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment