简体   繁体   中英

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?

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.

Use AsyncTask with progressDialog bounded, like here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM