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 ...
随机推荐
- 指尖上的电商---(12)SolrAdmin中加入多核的还有一种方法
这一节中我们演示下solr中创建多核的还有一种方法. 接第10讲,首先关闭tomcatserver 1.解压solr-4.8.0后,找到solr-4.8.0以下的example目录下的multicor ...
- Redis slowlog
和mongo的slowlog一样,redis中对于操作时间较长(默认为10秒)的命令也会记录下来,不过它将它们保存在redisServer结构中的slowlog这个链表中,新进来的log排在链表头部, ...
- dsp下基于双循环缓冲队列的视频采集和显示记录
对最近在设计的视频采集和显示缓冲机制做一个记录,以便以后使用. 视频采集和显示缓冲机制,其实是参考了Linux下v4L2的驱动机制,其采用输入多缓冲frame,输出多缓冲的切换机制.简单的就是ping ...
- 黑马程序员:Java基础总结----静态代理模式&动态代理
黑马程序员:Java基础总结 静态代理模式&动态代理 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 静态代理模式 public class Ts { ...
- PHP中如何实现 “在页面中一边执行一边输出” 的效果
<?php set_time_limit(0); //在有关数据库的大量数据的时候,可以将其设置为0,表示无限制. ob_end_clean(); //在循环输出前,要关闭 ...
- POI数据下载器
偶尔用点儿POI数据,所以写了一个下载器.用到的东西还真不少. 功能点 +编写翻页脚本 +CSharp与JS交互 +POI数据转换json +CSharp的json序列化类 +CSharp读写json ...
- SQL Server Database 维护计划创建一个完整的备份策略
SQL Server维护计划Maintenance Plan这是一个非常有用的维护工具,能够完成大部分的数据库维护任务,通过这些功能包.您可以省略大量的编码时间. 介绍的不是非常多,特此补上一篇 ...
- loj1336(数学)
传送门:Sigma Function 题意:定义f(n)为n的约数之和,求[1,n]中f值为偶数的数的个数. 分析:由题目给定公式可知,若f(n)为奇数,则相乘的每一项都必须为奇数. 每一项为奇数的条 ...
- cxf和jboss eap 6.2版本号冲突
升级jboss版本号到jjboss-eap-6.2之后,启动项目时CXF出现异常. 在jboss-as-7.1.1.Final.apache-tomcat-7.0.37以及jboss-eap-6.1 ...
- Hulu面试题解答——N位数去除K个数字(解法错误sorry)
给定一个N位数,比如12345,从里面去掉k个数字.得到一个N-k位的数.比如去掉2,4,得到135,去掉1,5.得到234.设计算法.求出全部得到的N-k位数里面最小的那一个. 写的代码例如以下,思 ...