在本文中,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;
@Override
protected 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 block
e.printStackTrace();
}
button.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {
//progressDialog.show();
new DownloadFilesTask().execute(url); }
}); } private class DownloadFilesTask extends AsyncTask<URL, Void, Void> { @Override
protected void onPreExecute() {
progressDialog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(URL... urls) {
httpUtils.sendDownloadPost(urls[0]);
return null;
} @Override
protected 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. 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. iOS学习——iOS国际化(十二)

    开发的移动应用更希望获取更多用户,走向世界,这就需要应用国际化,国际化其实就是多语言.这篇文章介绍Xcode4.5以后的国际化,包括应用名国际化和应用内容国际化.如果是Xcode4.5之前版本请参考. ...

  2. WCF(1)----服务创建

    本例中,我们通过一个关于Camera的服务为例子来说明WCF的开发流程,该服务比较简单,只是用来实现对Camera的添加,枚举,删除等操作. 详细步骤如下: 1:创建一个WCF Service Lib ...

  3. ZooKeeper安装与运行

    ZooKeeper安装与运行 首先从官网下载ZooKeeper压缩包,然后解压下载得到的ZooKeeper压缩包,发现有“bin,conf,lib”等目录.“bin目录”中存放有运行脚本:“conf目 ...

  4. 在MVC应用程序中动态加载PartialView

    原文:在MVC应用程序中动态加载PartialView 有时候,我们不太想把PartialView直接Render在Html上,而是使用jQuery来动态加载,或是某一个事件来加载.为了演示与做好这个 ...

  5. 【Python】Coding the Matrix:Week 5 Perspective Lab

    这个Lab的内容光是说明就有7页之巨,我反复看了很久才看懂一点点,Lab主要完成的是从不同坐标系表示之间变换的方法. 原始的图片,从Camera basis的表示转换成WhiteBoard basis ...

  6. Hdu 4734 【数位DP】.cpp

    题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~ ...

  7. Winform通用模块之流水号生成

    打算接下来的时间里把自己觉得用起来还比较好用的通用模块,在这里向大家介绍一下,如果你有更好的想法时,也希望你不吝指点. 1.数据库表及存储过程 在介绍这个通用流水号生成的模块前,我们先来看一下其相关的 ...

  8. MooTools,jQuery库的一些比对

    jQuery与MooTools库的一些比对   今天就我自己的一些认识比对下这两个JS框架,更多的是希望大家能够对MooTools这个JS框架有更多的认识.毕竟,大多数从事web前端的人对上手容易的j ...

  9. 内存分析工具 MAT 的使用

    1 内存泄漏的排查方法 Dalvik Debug Monitor Server (DDMS) 是 ADT插件的一部分,当中有两项功能可用于内存检查 : ·    heap 查看堆的分配情况 ·     ...

  10. 设计模式学习一:strategyPattern

    #ifndef STRATEGYPATTERN_H_#define STRATEGYPATTERN_H_#include<iostream>using namespace std; //策 ...