, android中实现了默认的进度提示对话框,即progressdialog,通过实例化和一些简单设置,就可以使用了。
对于写好的异步任务类,调用方法为:
注意asynctask为泛型类,具有三个泛型参数,此处设计为 <string, integer, string>,对应于运行参数、进度值类型和返回参数。
从sdk的文档中看到,当一个asynctask运行的过程中,经历了4个步骤:
1、onpreexecute(), 在excute调用后立即在ui线程中执行。 this step is normally used to setup the task, for instance by showing a progress bar in the user interface.
2、doinbackground, 当 onpreexecute() 完成后, 立即在后台线程中运行. this step is used to perform background computation that can take a long time. the parameters of the asynchronous task are passed to this step. the result of the computation must be returned by this step and will be passed back to the last step. this step can also use publishprogress to publish one or more units of progress. these values are published on the ui thread, in the onprogressupdate step.
3、onprogressupdate, 在调用publishprogress后,在ui线程中运行. the timing of the execution is undefined. this method is used to display any form of progress in the user interface while the background computation is still executing. for instance, it can be used to animate a progress bar or show logs in a text field.
4、onpostexecute, 后台运算完成时在ui线程中调用. the result of the background computation is passed to this step as a parameter.
如对本文有疑问, 点击进行留言回复!!
Android安卓水滴屏适配状态栏图标(图标过多时显示一个点)
android studio使用Flutter创建web项目
android如何使用taskAffinity属性对任务栈操作控制
android对PDF文件的操作(上传、预览、下载和转存相册)
Android通过代码批量生成字符图标用于给输入法显示状态栏的图标
网友评论