Skip to content

Instantly share code, notes, and snippets.

@blundell
Created August 6, 2019 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blundell/902d7283489a5eb2edda7823d4a38b05 to your computer and use it in GitHub Desktop.
Save blundell/902d7283489a5eb2edda7823d4a38b05 to your computer and use it in GitHub Desktop.
Listener Example
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