I've got a problem with a button click. When user clicks on my button, the screen is blocked for some seconds, because of the operations that activity has to execute. If I want to open a toast notification that displays a loading message, how I can execute theese operations in background? And if result is ok, how I can kill previous activity and open an other one?
Asked
Active
Viewed 206 times
0
-
See [this](http://stackoverflow.com/questions/3264383/difference-between-service-async-task-thread) related question for various ways of doing things in the background. – Delyan May 04 '11 at 13:18
2 Answers
4
You should use AsyncTask. It was created for just this purpose:
Show ProgressDialog in AsyncTack.onPreExecute() method. Toast is not fit for this task as you can not control how long it is shown.
Do work in AsyncTack.doInBackground() method.
When done, AsyncTack.onPostExecute() will be called: cancel dialog, start new activity.

Peter Knego
- 79,991
- 11
- 123
- 154