Vito Gentile
Vito Gentile

Reputation: 14386

Android: Non-blocked screen on button click

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?

Upvotes: 0

Views: 216

Answers (2)

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43108

Use AsyncTask with progressDialog bounded, like here.

Upvotes: 0

Peter Knego
Peter Knego

Reputation: 80340

You should use AsyncTask. It was created for just this purpose:

  1. Show ProgressDialog in AsyncTack.onPreExecute() method. Toast is not fit for this task as you can not control how long it is shown.

  2. Do work in AsyncTack.doInBackground() method.

  3. When done, AsyncTack.onPostExecute() will be called: cancel dialog, start new activity.

Upvotes: 4

Related Questions