What are good strategies for handling asynchronous callbacks on Android?
<p>An app may have parts that run on separate threads and call back to some object when finished. A typical pattern may look like: </p>

<p>1) a View or Fragment makes a call to some model. The call originates from some View or Fragment</p>

<pre><code>model.doSomething(context, new Runnable() {
    public void run() { /* run on the main thread when model finishes */ }
});
</code></pre>

<p>2) a model uses a Thread or AsyncTask that does something and then calls the callback on the  calling thread - using a Handler </p>

<pre><code>void doSomething(Context context, Runnable callback) {
    Handler handler = new Handler();
    // ...
    // When finished (this is really done on some separate thread),
    handler.post(callback);
} 
</code></pre>

<p>3) the callback interacts with calling View or Fragment to advance through some control logic</p>

<p>The callback may be touching state of a View that's not attached to a window, which may lead to instability in the app.</p>

<p>What are some good strategies to handle this situation?</p>
