Loading an Alert Box from a Thread when the activity has gone away
I have a comment activity that loads a Thread and sends some data to a server; the activity is immediately finished once the submit button is pressed.
The user 开发者_JAVA技巧is then free to do other things in my application.
When the server responds an AlertDialog
is shown.
The problem is that since the initial context has been destroyed, my application crashes.
I tried getApplicationContext()
but still get an exception.
Put your network stuff in a Service, then show a status bar notification instead of a dialog.
Take a look at AsyncTask
From JavaDocs: AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
精彩评论