I'm using UIL (by Nosotra) to download images that the server renders, and it takes the server up to 50 seconds to create each image. The server's timeout is set to 15 seconds, so we've created a polling mechanism that is implemented in the ImageDownloader.getStream() method. After downloading, the images are displayed in a ViewPager (android.support.v4.view.ViewPager, just as the sample does.)

我正在使用UIL(通过Nosotra)下载服务器渲染的图像,并且服务器最多需要50秒来创建每个图像。服务器的超时设置为15秒,因此我们创建了一个在ImageDownloader.getStream()方法中实现的轮询机制。下载后,图像将显示在ViewPager(android.support.v4.view.ViewPager中,就像示例一样。)

When users navigate to other pages, I wish to stop the polling without downloading files, but it seems there's no "nice" way to break the downloading flow.

当用户导航到其他页面时,我希望在不下载文件的情况下停止轮询,但似乎没有“好”方法来打破下载流程。

getStream Pseudo-code

1. Parse custom-style URI ("asdf://mypng|123455678945643563245");
2. Make a real world URL from it.
3. Poll the server for the image url (causes the server to render - could take up to 1m30s).
4. Get the stream from the URL, return the stream to caller. 
       Example Code: InputStream is = (InputStream) url.getContent();

What's tried so far

到目前为止尝试了什么

Returning null from my getStream method causes an NullPointerException to be thrown, so it's basically same as just throwing an exception.

从我的getStream方法返回null会导致抛出NullPointerException,因此它与抛出异常基本相同。

When an exception is thrown, the image does stop, but:

抛出异常时,图像会停止,但是:

  1. A few images later, I get an OutOfMemoryError, so I show an error on screen. I shouldn't get the error. I already tried this SO question's checklist, but nothing worked. This is the OOM Stacktrace:OutOfMemoryError stacktrace nostra uil
  2. 稍后几张图片,我得到一个OutOfMemoryError,所以我在屏幕上显示错误。我不应该得到错误。我已经尝试过这个SO问题的清单,但没有任何效果。这是OOM Stacktrace:

  3. The downloading stops, and if the viewer won't recycle the view, when returning to that page, I'll still see that error page (no retry).
  4. 下载停止,如果查看器不回收视图,当返回到该页面时,我仍然会看到该错误页面(不重试)。

What I wish

我希望如何

I wish for me to have a "wait" method that would add stop the current download and re-add a new task to the end of the queue (currently on set on a QueueProcessingType.LIFO, and I wish it to download the re-added after after current pages, and any new pages the user wants should have precedence over the re-added ones).

我希望我有一个“等待”方法,可以添加停止当前下载并重新添加一个新任务到队列的末尾(当前在QueueProcessingType.LIFO上设置,我希望它下载重新下载在当前页面之后添加,并且用户想要的任何新页面应该优先于重新添加的页面。

I would also settle for avoiding the OutOfMemoryError.

我也愿意避免OutOfMemoryError。

Please help.

1 个解决方案

#1


1

Problem could be here 4. Download the image, return the stream. Downloading - it is main feature of UIL. Just return the NetworkStream here. Also I had OOM on UIL with large Images and enabled MemoryCache. Also which image size do you have on server. in load Image method you have control on Size. Also so helpful UIL GitHub please read 3 and 4 paragraph.

问题可能在这里4.下载图像,返回流。下载 - 这是UIL的主要特色。只需在此处返回NetworkStream即可。我还在UIL上使用大图像和启用了MemoryCache。您在服务器上也有哪个图像大小。在加载Image方法中,您可以控制Size。也很有帮助UIL GitHub请阅读3和4段。

更多相关文章

  1. fragment保存页面不销毁
  2. Android欢迎页面自动跳转和触摸进入首页
  3. 通过ViewPager实现类似微信的页面切换(Fragment篇)
  4. android开发中如何从当前页面返回上一页面
  5. 在不同状态下使用两个图像切换按钮
  6. 在Webview上加载脱机更新页面
  7. 自定义BaseAdapter,在主Activity页面调用显示歌曲列表
  8. 提取Launcher中的WorkSapce,可以左右滑动切换屏幕页面的类
  9. 如何将值发送到Ionic中具有条件的其他页面

随机推荐

  1. Android模仿Buttonbar(style="@android:st
  2. Selector的一些state使用
  3. Android Binder机制学习总结(二)-Driver
  4. Android C 语言读取系统属性
  5. Android ImageView实现上一页,下一页图片
  6. 在ListFragment中使用base-adapter
  7. 使用bitmap缩略图,解决图片大小超过预算的
  8. Android Activity四种加载方式
  9. android 学习之安装
  10. Android(安卓)databinding RecycleView i