Android含文档server结束(client UI接口异步请求的一部分)三
在本文中,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>
主要有三个參数
Params, the type of the parameters sent to the task upon execution. 本文传递URL数据Progress, the type of the progress units published during the background computation.//进度条Result, the type of the result of the background computation. //结果
本文未採用进度条形式,仅仅使用了ProgressDialog,故第二个參数置为空,第三个參数选取时,本文在httpUtils包类已经写入文件到sd卡,故也置为空。
重写的方法:
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主线程中,初始化參数doInBackground(Params...),
invoked on the background thread immediately afteronPreExecute()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 usepublishProgress(Progress...)to
publish one or more units of progress. These values are published on the UI thread, in theonProgressUpdate(Progress...)step.
非主线程。耗时操作onProgressUpdate(Progress...),
invoked on the UI thread after a call topublishProgress(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.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接口异步请求的一部分)三的更多相关文章
- Androids含文档erver结束(工具包 Httputils)两
在同server在...的基础上,本文client还登录界面 Andriod简单http get请求基础上,用户注冊后跳转到下载界面,本文下载界面仅仅有两个View,一个是textView显示注冊后u ...
- 提高打开Android本地文档的速度
非常多Android开发人员在參考Android官方API时,都有一个令人头疼的问题:打开一个index.html平均都须要几分钟甚至更长.尤其是在打开API 8以上的版本号的时候.难道是网速不够好? ...
- Android SDK文档如何查找
肯定很多人都会有疑问,怎样使用Android SDK 文档该如何使用呢?里面有那么多内容,又全是英文的,接下来告诉大家. 以下内容来自网络. ----------------------------- ...
- 三种方法解决android帮助文档打开慢
三种方法解决android帮助文档打开慢 经查是因为本地文档中的网页有如下两段js代码会联网加载信息,将其注释掉后就好了 <link rel="stylesheet" h ...
- Android XML文档解析(一)——SAX解析
---------------------------------------------------------------------------------------------------- ...
- Android 开发者文档 -- 应用基础知识
https://developer.android.com/guide/components/fundamentals 应用基础知识 Android 应用采用 Java 编程语言编写.Android ...
- 关于android帮助文档打开慢
打开慢的原因是:Doc目录下的html文件里含有访问google的js文件<link rel="stylesheet"href="http://fonts.goog ...
- Android API 文档 离线秒开方法
http://blog.csdn.net/haifengzhilian/article/details/39898627 也是最近才看Android开发,但是,它的API文档无论是在线还是离线的,实在 ...
- 安装的Android SDK下无doc文件夹问题 以及关联Android帮助文档和查看文档 以及查看在线文档
参考连接:https://blog.csdn.net/fangzicheng/article/details/78344521 https://jingyan.baidu.com/article/29 ...
随机推荐
- [置顶] android开发之来电自动拒接并自动回复短信_上课模式app
上课的时候老师说总是错过电话,对方打来没人接还一遍遍的打,觉得可以有个app在上课期间自动拒接电话,并自动回复短信过去. 当然了,需要权限的. 尝试做了个雏形出来. 界面如下: 主要代码如下: pac ...
- 开启程序的Visual Styles
首先看看MS对Visual Styles的解释: Windows XP and later operating systems support a feature called visual styl ...
- POJ 1122 FDNY to the Rescue!
给出某些交叉点的距离,-1 表示无法到达. 然后给出火灾发生点 和 附近的消防局位置. 排列消防局 的 时间 与路径. 反向建图,以火灾出发点为起点做一次SPFA. #include<cstd ...
- POJ 2365 Rope(水题)
[题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们能够看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度事实上就 ...
- hdu 2451 Simple Addition Expression(数位DP )成败在于细节
亚洲区域赛的题,简单的数位DP题,注重细节. 任何细节都有可能导致wa,所以没有绝对的水题. 把握好细节,此题便A. #include<stdio.h> __int64 getans(__ ...
- asp.net mvc4中自定义404页面
原文地址:http://www.chuchur.com/asp-net-mvc4-404/ 定义404 方法当然有很多种.不同的方法所展现的形式也不一样,用户所体验也不一样.以下提供2两种 方法一: ...
- BaiduMap_SDK_DEMO_3.0.0_for_Xamarin.Android_by_imknown
2.4.2 已稳定, 同一时候已经放置到分支/Release 2.4.2了. 3.0.0 已开发完毕, 可是不推荐大家用于项目中, 请观望或者自己进一步调试. 个人感觉尽管3.0.0简化了开发, 可是 ...
- httl开源JAVA模板引擎,动态HTML页面输出
HTTL(Hyper-Text Template Language)是一个适用于HTML输出的开源JAVA模板引擎,适用于动态HTML页面输出,可用于替代JSP页面,它的指令类似于Velocity. ...
- java7 API详解
Java™ Platform, Standard Edition 7API Specification This document is the API specification for the J ...
- gcc的bug? c++模板类中友元函数的訪问权限问题
原文地址:http://stackoverflow.com/q/23171337/3309790 在c++中,模板类中能够直接定义一个友元函数.该函数拥有訪问该模板类非public成员的权限. 比方: ...