Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android的AsynTask中挂起所有线程需要时间_Java_Android_Android Asynctask_Http Get - Fatal编程技术网

Java 在android的AsynTask中挂起所有线程需要时间

Java 在android的AsynTask中挂起所有线程需要时间,java,android,android-asynctask,http-get,Java,Android,Android Asynctask,Http Get,我正在尝试使用下面的代码从Android服务器获取图像(15个图像) 使用以下代码调用AsynTask: DownloadImageSequencially lmib=新的DownloadImageSequencially(); Lmib.execute(分割图像) 这里SplitImages是图像URL的数组。 class DownloadImageSequencially扩展异步任务 { @凌驾 受保护的Void doInBackground(对象…参数){ //TODO自动生成的方法存根

我正在尝试使用下面的代码从Android服务器获取图像(15个图像)

使用以下代码调用AsynTask:

DownloadImageSequencially lmib=新的DownloadImageSequencially(); Lmib.execute(分割图像)

这里SplitImages是图像URL的数组。
class DownloadImageSequencially扩展异步任务
{
@凌驾
受保护的Void doInBackground(对象…参数){
//TODO自动生成的方法存根
对于(int indx=0;indx9){
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
}
Log.e(“Masthan2”、“Masthan2”);
HttpResponse response=client.execute(getRequest);
Log.e(“Masthan3”、“Masthan3”);
//检查200 OK是否成功
final int statusCode=response.getStatusLine().getStatusCode();
Log.e(“Masthan4”、“Masthan4”);
if(statusCode!=HttpStatus.SC\u OK){
Log.w(“ImageDownloader”,“Error”+状态码+
从“+url”检索位图时);
}
最终HttpEntity=response.getEntity();
Log.e(“Masthan5”、“Masthan5”);
如果(实体!=null){
InputStream InputStream=null;
试一试{
//从流中获取内容
inputStream=entity.getContent();
Log.e(“Masthan6”、“Masthan6”);
//将流数据解码回android理解的图像位图
bitmapArray[indx]=BitmapFactory.decodeStream(inputStream);
Log.e(“Masthan7”、“Masthan7”);
}最后{
Log.e(“Masthan8”、“Masthan8”);
如果(inputStream!=null){
Log.e(“Masthan9”、“Masthan9”);
inputStream.close();
Log.e(“Masthan10”、“Masthan10”);
}
entity.consumercontent();
Log.e(“Masthan11”、“Masthan11”);
}
}
}捕获(例外e){
//您可以为IOException提供更明确的错误消息
getRequest.abort();
Log.e(“ImageDownloader”,“运行时出错”+
从“+url+e.toString())检索位图;
}
}

}
您正在使用单个asynctask线程下载多个文件。因此,显然,如果文件计数较高,则需要更多时间。如果您希望同时下载多个文件,请尝试使用


请参阅此处:-

图像有多大?每个图像的大小不超过100 KB。我已尝试过链接中提到的方法。但我有一个问题:如何将执行器服务逻辑应用于AsyncTask。请给我示例程序…请参阅此处,我已尝试过链接中提到的方法。但我有这个问题