简体   繁体   中英

Does Asynctask require a progress dialog?

I've been using Asynctask for calling API methods, and use ProgressDialog to show the user that a process is ongoing and they could not use the background unless the process is done or Asynctask is already in onPostExecute .

Going back to the question, is the ProgressDialog really required to show the progress and to prohibit the user from doing anything in the background?

Does Asynctask require a progress dialog?

No.

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.

Programmatically: The progress dialog is introduced when there is a dependency on the async task to complete or reach a particular stage before there is further non-exception resulting interaction from the user.

There is a UI angle to it, which in the specified case engages the user visually or by animation which is a good practice when the app is not 'doing' anything for the user.

Android Ref:AsyncTask

More on Why to use Async task

is the ProgressDialog really required to show the progress and to prohibit the user from doing anything in the background?

Nope, Asynctasks can be used with or without progress dialogs or progress bars. Progress dialogs are optional and one reason of their usage is to make your user know that there is currently a process that is happening in the background.

Ref: http://developer.android.com/reference/android/os/AsyncTask.html

Nope. It's just something you can show to the user if you need to wait for a response. Even if you don't, your AsyncTask will still execute in the background and do what it was supposed to. The whole point of using an AsyncTask is to stop the UI from getting blocked.

For example : You might not use a progress dialog in case you just want to send some sort of update to a server. Such as telling the server that your app was started at this particular time. The user does not need to know about this. So you just execute an AsyncTask in the background and let the user the App normally while the update happens in the background without the user ever knowing.

Is the ProgressDialog really required to show the progress and to prohibit the user from doing anything in the background?

Incase if you're using to many activities inside the doinBackground , you must have to specify something on the progress update such as loading ,or please wait ,else if you have a very little operation,just leave that progressupdate.

is the ProgressDialog really required to show the progress

Displaying ProgressDialog while using AsyncTask is optional AFAIK. But you must understand the purpose of using ProgressDialog in AsyncTask . It is used to discourage the user from performing any interaction with the application while the task is running. Or you may want to simply let them know that something is happening in the background.

Not Necessary.

The simple use of Progress Dialog in AsyncTask is used to keep end user engage when performing long running progress.

It depends on what your application is all about and how frequent you are calling your AsyncTask, if you are making call to AsyncTask too frequent for eg 1-2 calls/ minute then this might be a bad design practice, Your users will be annoyed by progress dialog showing frequently, this will also reduce battery life and consume more data bandwidth. Instead you should try and batch all your request with one call. Have a look at this link it might give you a head start http://developer.android.com/training/efficient-downloads/efficient-network-access.html

A ProgressDialog is not required, but it's a good practice, as it informs the user on an ongoing task and it halts from executing possibly another AsyncTask .
While one AsyncTask is being run in background, another one is run, parallel run is hardly supported.
It is a good practice, as far as I am concerned to use a ProgressDialog , as when ProgressDialog dismisses, the AsyncTask is completed and there can't be parallel execution.
See this one. Running multiple AsyncTasks at the same time -- not possible?

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