在本文中,AsyncTask为了实现异步请求,详细代码如下所示的:

public class downloadActivity extends Activity {private TextView myTextView=null;private Button button=null;private static final String path="http://192.168.0.179:8080/Myweb/download.do";private ProgressDialog progressDialog=null;private URL url=null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.download);//获取传过来的用户名Intent intent = getIntent();String value = intent.getStringExtra("username");value="hello"+" "+value;//myTextView = (TextView) findViewById(R.id.textView1);myTextView.setText(value);button=(Button)this.findViewById(R.id.download_btn);progressDialog=new ProgressDialog(this);progressDialog.setCancelable(false);progressDialog.setTitle("提示");progressDialog.setMessage("请耐心等待,文件正在下载中....");try {url=new URL(path);} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();}button.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {//progressDialog.show();new DownloadFilesTask().execute(url);}});}private class DownloadFilesTask extends AsyncTask<URL, Void, Void> {@Overrideprotected void onPreExecute() {progressDialog.show();super.onPreExecute();}@Overrideprotected Void doInBackground(URL... urls) {httpUtils.sendDownloadPost(urls[0]);return null;} @Overrideprotected void onPostExecute(Void result) {progressDialog.dismiss();super.onPostExecute(result);}}}

在注冊时,使用Intent传递了username数据。

AsyncTask<URL, Void, Void>

主要有三个參数

  1. Params, the type of the parameters sent to the task upon execution.  本文传递URL数据
  2. Progress, the type of the progress units published during the background computation.//进度条
  3. Result, the type of the result of the background computation.  //结果

本文未採用进度条形式,仅仅使用了ProgressDialog,故第二个參数置为空,第三个參数选取时,本文在httpUtils包类已经写入文件到sd卡,故也置为空。

重写的方法:

  1. onPreExecute(), invoked on the UI thread immediately after the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.  UI主线程中,初始化參数
  2. doInBackground(Params...), invoked on the background thread immediately after onPreExecute() finishes executing. 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(Progress...) to publish one or more units of progress. These values are published on the UI thread, in theonProgressUpdate(Progress...) step.  非主线程。耗时操作
  3. onProgressUpdate(Progress...), invoked on the UI thread after a call to publishProgress(Progress...). 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(Result), invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.  结果更新

Android含文档server结束(client UI接口异步请求的一部分)三相关推荐

  1. Android入门文档

    该文章为网络材料整理,部分内容经过重新编写. 一. 名词介绍 JDK:Java Development Kit Java 语言的软件开发工具包 JRE:Java Runtime Environment ...

  2. android sdk 文档导读之前传:初涉

    看到csdn博客上面其它大牛的系列性android博客,小弟确实十分羡慕.所以经过一番思想斗争后,小弟终于要打算写写系列性的博客了.通过对一些选题的推敲,我决定对android的sdk文档进行一个比较 ...

  3. [含文档+源码等]微信小程序校园生活小助手+后台管理系统前后分离VUE[包运行成功]

            博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 [含文档+源码等]微信小程序校园生活小助手+后台管理系统前后分离V ...

  4. springboot mybatis大学生校园宿舍管理系统源码含文档

    摘 要:宿舍是大学生学习与生活的主要场所之一,宿舍管理是高校学工管理事务中 尤为重要的一项.随着我国高校招生规模的进一步扩大,学生总体人数的不断增加, 宿舍管理工作变得愈加沉重和琐碎,学生宿舍信息的采 ...

  5. [含文档+源码等]高校科研项目管理系统[包运行成功]

       博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 [含文档+源码等]高校科研项目管理系统[包运行成功] 演示视频 视频去哪了呢 ...

  6. 含文档+PPT+源码等]精品基于SSM的图书管理系统[包运行成功]

     博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 含文档+PPT+源码等]精品基于SSM的图书管理系统[包运行成功] 系统介绍 & ...

  7. [含文档+PPT+源码等]基于SSM个人财务记账账单收入支出统计管理系统[包运行成功]

       博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 [含文档+PPT+源码等]基于SSM个人财务记账账单收入支出统计管理系统 系 ...

  8. [含文档+PPT+源码等]基于SSM个人财务记账账单收入支出统计管理系统

      博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 [含文档+PPT+源码等]基于SSM个人财务记账账单收入支出统计管理系统 系统 ...

  9. [含文档+源码等]基于SSM实现的宿舍公共财产管理系统|寝室

      博主介绍:✌在职Java研发工程师.专注于程序设计.源码分享.技术交流.专注于Java技术领域和毕业设计✌ 项目名称 [含文档+源码等]基于SSM实现的宿舍公共财产管理系统|寝室 演示视频 [含文 ...

最新文章

  1. oracle使用小技巧
  2. 互链网-未来世界的连接方式 (1)央行数字货币CBDC模型
  3. 解决Button设置disabled后无法执行后台代码问题
  4. Android 圆角Button
  5. mybatis-MyBatis-Plus
  6. ALAssetsLibrary获取相册列表
  7. 【Python】Python2.7.15 - Windows安装Python以及Python安装目录结构详解
  8. 【Elasticsearch】cannot allocate because allocation is not permitted to any of the nodes
  9. scrapy shell 用法(慢慢更新...)
  10. CSS 文字超出长度的显示省略号的方法总结
  11. kafka--Struct Streaming--console案例入门
  12. 为IDEA配置maven镜像
  13. 免费的网站地图生成器,sitemap支持xml、html、txt生成绝对站长工具必备使用教程
  14. Linux内核崩溃转存,Ubuntu 12.04 配置内核崩溃自动重启及转存
  15. html js日历制作视频,JS实现日历制作
  16. 山重水复疑无路,分库分表来敲门
  17. python自动翻译excel某一列_python批量将excel内容进行翻译写入功能
  18. 如何用微信公众号快速注册小程序
  19. 字节跳动Java研发面试总结:2个星期,4轮面试,我终于拿到offer
  20. APP种树微信小程序源码下载-简单快速上手

热门文章

  1. 简述对linux系统的认识,对Linux的认识
  2. MATLAB程序实验3,实验3_matlab程序设计实验.doc
  3. python中argsort_浅述python中argsort()函数的实例用法
  4. linux mvn m2目录,Maven C盘用户文件下没有.m2
  5. can使能上拉 gpio_单片机GPIO输入电压不可过大,最好使能上拉
  6. Spring Security HttpSecurity
  7. pytorch tensor 梯度
  8. 网络通信 URL-省略文件名情况
  9. freecplus框架-日志文件操作
  10. Oracle环境变量