【问题标题】:Intent Service display image in ImageViewImageView 中的 Intent Service 显示图像
【发布时间】:2018-03-21 10:25:27
【问题描述】:

我想使用 Intent Service 在图像视图中显示在线图像。

public class IntentServiceClass extends IntentService {
public IntentServiceClass() {
    super("IntentServiceClass");


}

@Override
protected void onHandleIntent( Intent intent) {
    if (intent != null) {
        String URLImage = "https://tortoisesvn.net/assets/img/logo-256x256.png";
      Bitmap bmp = null;
        try{
            InputStream inputStream = new java.net.URL(URLImage).openStream();
            bmp = BitmapFactory.decodeStream(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    }

}

我不知道我是否做错了以及如何继续。 有人可以帮帮我吗?

【问题讨论】:

  • 你确定你在问什么?
  • 为什么使用IntentService 来完成这样的任务使用图像加载器而不是Glide
  • 我只能使用 Intent Service,不能使用任何其他方法。

标签: android image android-intent service show


【解决方案1】:

您不能从Service 直接访问Activity 中的ImageView(或任何View),这里有一篇关于如何做到这一点的文章:Ways to communicate between Activity and Service

但是,在您的情况下,我建议您不要使用IntentService 来加载图像。考虑在流行的图像加载库 s.a. 上使用PicassoGlideUniversalImageLoader

【讨论】:

    【解决方案2】:

    将图像显示到 ImageView 中。 您可以使用GlidePicasso。从活动中,代码将喜欢:

    毕加索

      Picasso.get().load(url).resize(50, 50).centerCrop().into(imageView)
    

    滑行

      Glide.with (context)
         .load ( "http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg")
         .into (imageView);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      相关资源
      最近更新 更多