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

  1. public class downloadActivity extends Activity {
  2.  
  3. private TextView myTextView=null;
  4. private Button button=null;
  5. private static final String path="http://192.168.0.179:8080/Myweb/download.do";
  6. private ProgressDialog progressDialog=null;
  7. private URL url=null;
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10.  
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.download);
  13.  
  14. //获取传过来的用户名
  15. Intent intent = getIntent();
  16. String value = intent.getStringExtra("username");
  17. value="hello"+" "+value;
  18. //
  19. myTextView = (TextView) findViewById(R.id.textView1);
  20. myTextView.setText(value);
  21. button=(Button)this.findViewById(R.id.download_btn);
  22. progressDialog=new ProgressDialog(this);
  23. progressDialog.setCancelable(false);
  24. progressDialog.setTitle("提示");
  25. progressDialog.setMessage("请耐心等待,文件正在下载中....");
  26. try {
  27. url=new URL(path);
  28. } catch (MalformedURLException e) {
  29. // TODO Auto-generated catch block
  30. e.printStackTrace();
  31. }
  32. button.setOnClickListener(new OnClickListener() {
  33.  
  34. public void onClick(View arg0) {
  35. //progressDialog.show();
  36. new DownloadFilesTask().execute(url);
  37.  
  38. }
  39. });
  40.  
  41. }
  42.  
  43. private class DownloadFilesTask extends AsyncTask<URL, Void, Void> {
  44.  
  45. @Override
  46. protected void onPreExecute() {
  47. progressDialog.show();
  48. super.onPreExecute();
  49. }
  50. @Override
  51. protected Void doInBackground(URL... urls) {
  52. httpUtils.sendDownloadPost(urls[0]);
  53. return null;
  54. }
  55.  
  56. @Override
  57. protected void onPostExecute(Void result) {
  58. progressDialog.dismiss();
  59. super.onPostExecute(result);
  60. }
  61. }
  62.  
  63. }

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

  1. 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. Androids含文档erver结束(工具包 Httputils)两

    在同server在...的基础上,本文client还登录界面 Andriod简单http get请求基础上,用户注冊后跳转到下载界面,本文下载界面仅仅有两个View,一个是textView显示注冊后u ...

  2. 提高打开Android本地文档的速度

    非常多Android开发人员在參考Android官方API时,都有一个令人头疼的问题:打开一个index.html平均都须要几分钟甚至更长.尤其是在打开API 8以上的版本号的时候.难道是网速不够好? ...

  3. Android SDK文档如何查找

    肯定很多人都会有疑问,怎样使用Android SDK 文档该如何使用呢?里面有那么多内容,又全是英文的,接下来告诉大家. 以下内容来自网络. ----------------------------- ...

  4. 三种方法解决android帮助文档打开慢

    三种方法解决android帮助文档打开慢   经查是因为本地文档中的网页有如下两段js代码会联网加载信息,将其注释掉后就好了 <link rel="stylesheet" h ...

  5. Android XML文档解析(一)——SAX解析

    ---------------------------------------------------------------------------------------------------- ...

  6. Android 开发者文档 -- 应用基础知识

    https://developer.android.com/guide/components/fundamentals 应用基础知识 Android 应用采用 Java 编程语言编写.Android ...

  7. 关于android帮助文档打开慢

    打开慢的原因是:Doc目录下的html文件里含有访问google的js文件<link rel="stylesheet"href="http://fonts.goog ...

  8. Android API 文档 离线秒开方法

    http://blog.csdn.net/haifengzhilian/article/details/39898627 也是最近才看Android开发,但是,它的API文档无论是在线还是离线的,实在 ...

  9. 安装的Android SDK下无doc文件夹问题 以及关联Android帮助文档和查看文档 以及查看在线文档

    参考连接:https://blog.csdn.net/fangzicheng/article/details/78344521 https://jingyan.baidu.com/article/29 ...

随机推荐

  1. Bdsyn百度手机助手是何物,它是怎样神不知鬼不觉地安装到你的电脑里的?

    [电脑软件管理中Bdsyn手机助手的问题]Bdsyn手机助手 is developed by Baidu, Inc. and is used by 10 users of Software Infor ...

  2. [.NET Framework学习笔记]一些概念

    CIL:Common Intermediate Language 公共中间语言 VB.NET 和 C#.NET 编译以后都生成相同的中间语言,程序集就是由CIL组成的,CIL代码也叫做托管代码,因为C ...

  3. phing用户手册第四章Getting Started译文

    本章是phing的入门篇,查看 原文请猛击这里. XML And Phing 一个合法的Phing构建文件有以下几部分构成: 1.文档序言 2.唯一的根元素<project> 3.一些Ph ...

  4. 从零開始制作H5应用(4)——V4.0,增加文字并给文字加特效

    之前,我们分三次完毕了我们第一个H5应用的三个迭代版本号: V1.0--简单页面滑动切换 V2.0--多页切换,透明过渡及交互指示 V3.0--加入loading,music及自己主动切换 这已经是一 ...

  5. POJ 1122 FDNY to the Rescue!

    给出某些交叉点的距离,-1 表示无法到达. 然后给出火灾发生点  和 附近的消防局位置. 排列消防局 的 时间 与路径. 反向建图,以火灾出发点为起点做一次SPFA. #include<cstd ...

  6. Java I/O— 梳理各种“流”

    背景 Java核心库java.io它提供了一个综合IO接口.包含:文件读写.标准装备输出等..Java在IO它是流为基础进行输入输出的.全部数据被串行化写入输出流,或者从输入流读入. -- 百度百科 ...

  7. 基于CefGlue的桌面应用开发

    原文地址:http://johnnyfee.github.io/csharp/2013/12/21/cef-glue/ 前言 如果你想使用WEB技术来开发桌面客户端,并且是想使用的语言也是C#时,那请 ...

  8. Music Studio项目心得--JNI实现C++调用JAVA

    这个项目是我參加内蒙古挑战杯的比赛项目,因为时间关系,我没时间实现OpenOMR开源项目由JAVA全然向C++的转换,经过我半个多月的尝试,我将OpenOMR中的1/3的代码改写成C++,只是非常快我 ...

  9. SE 2014年4月22日(二)

    如图配置: 网络中存在三个公有AS 其中AS200使用了 BGP联盟技术(如图配置) 在AS 100 中R1上起源了四条BGP路由,(1)要求全网BGP设备均能够正常学习 (2)要求:(使用BGP团体 ...

  10. AJAX基础知识点学�

    1.AJAX(Asynchronous JavaScript and XML)即,异步JavaScript和XML 2.同步/异步差别 同步: ①每次进行整个页面的刷新 ②同步的链接在同一时间仅仅能有 ...