How can I tell if my context is still valid?
<p>I'm working with a fairly common situation right now - download some data over the web, then update a view to display it.  Clearly, I want to do the web download in the background, and then update the view on the main UI thread.  Now looking at my code, I'm a little worried about my Activity and its UI elements being killed off before I update them.  Here's the essence of what I have in mind:</p>

<pre><code>    Thread update = new Thread() {
        public void run() {
            final Data newData = requestData();                     
            if (newData != null) {                                              
                    post(new Runnable() {
                        public void run() {
                                Toast.makeText(MyClass.this, "I'll do things here that depend on my context and views being valid", Toast.LENGTH_SHORT).show();                                                             
                        }
                    });
            }
        }
    };
    update.start();
</code></pre>

<p>It seems possible that while I'm downloading data, the activity may be destroyed.  What happens then?  Will my thread continue to execute?  Will I end up trying to access dead objects?</p>

<p>Usually I do this by AsycTask, but the work seemed simple enough this time to just inline the threads-launching-threads stuff. Will I make things any better by using an AsyncTask instead?</p>
