android.app.Application invoking ArrayAdapter.notifyDataSetChanged
<p>I have a static class which extends android.app.Application (<strong>HireApplication</strong>) which is doing a lot of my background work. I create AsyncTasks here, I store the largest data objects that my application uses. I'm writing this code in the Application class so that I can reuse it between separate activities for Phones and Tablets.</p>

<p>This feels like the right way to layout my app, but now I have a problem. An AsyncTask has finished and needs to run notifyDataSetChanged on an ArrayAdapter within a Fragment (<strong>ListFragment</strong>).</p>

<p>Here is my solution:</p>

<p><strong>ListFragment:</strong></p>

<pre><code>public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    myListAdapter = new MyListAdapter(getActivity(), HireApplication.myList);
    HireApplication.myListAdapter = myListAdapter; // Tell the application where the ListView is so that it can notifyDataSetChanged
}
</code></pre>

<p><strong>HireApplication:</strong></p>

<pre><code>public static ArrayAdapter&lt;BikeStation&gt; stationListAdapter = null;

private static void asyncTaskCompleteCallback() {
    {...}
    myListAdapter.notifyDataSetChanged();
}
</code></pre>

<p>Now, this works... but it doesn't feel right. I am giving the Application a reference back to a UI element which sounds like it's a bit tightly coupled, but I don't know a better way to do this.</p>

<p>Is there a better way of my Application notifying my ArrayAdapter or Fragment that it should take some action to update the UI with fresh data?</p>

<p>Cheers.</p>
