Skip to content
Lautaro Brasseur edited this page Jun 29, 2018 · 1 revision

Loop

The Looper interface represents a component that can post tasks to be executed at the end of the UI loop. It should be used to ensure that logic is executed on UI thread.

Typically, you will inject it so a platform-specific implementation is provided:

public class LooperExample {
    private final Looper looper;

    @Inject
    public LooperExample(Looper looper) {
        this.looper = checkNotNull(looper);
    }

    public void doSomething() {
        looper.post(() -> doSomethingOnUiThread("Hi1"));
    }

    private void doSomethingOnUiThread(String data) {
        //...
    }
}

Clone this wiki locally