Use AsyncTask to implement this. Override doInBackground to receive the data (executed in a separate thread), then override onPostExecute () to show the toast (it runs in the user interface thread).
Here is a good example http://www.screaming-penguin.com/node/7746
And here are the official documents .
UPD: An example of how to handle partial progress.
class ExampleTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... params) {
while(true){
this.publishProgress("Some progress");
boolean stop = true;
if(stop){
break;
}
}
return "Result";
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
}
source
share