使用 View.setTag 作为记录图像哈希的方法是否安全?

Is it safe to use View.setTag as a way to record an image's hash?

我计划使用 View.setTag(int, Object) 存储 Uri 对象的哈希码,然后再通过 PicassoGlide 将其加载到 AppCompatImageView

我想知道,在 android 生命周期中,是否会有 AppCompatImageView 被销毁并重新创建的时间 - 保留来自 setTag 的信息而不是实际图像本身 - 从而造成不一致。

我能保证只要setTag存在,加载的图片也会存在吗?

I plan on using View.setTag(int, Object) to store the hashcode of a Uri object before loading it into an AppCompatImageView via Picasso or Glide.

回到 ListView 优化时代,我们使用 View.setTag(int, Object) 来存储特定视图的信息,以便在重绘时重用,记住重绘这个词不会重新创建。所以我们可以说直到视图的对象被保留或者换句话说视图没有被破坏,它是安全的。

I was wondering, during the android lifecycle, will there ever be a time when the AppCompatImageView gets destroyed and recreated - retaining the information from setTag but not the actual image itself - thereby creating inconsistency.

在更好的情况下,这不应该发生。考虑设备旋转的情况,将创建并绘制一个新视图,因此它不会保存最后设置的标签的信息。

Am I guaranteed that as long as setTag exists, the loaded image will also exist?

这么说吧,imageView.setTag(int, Object) 会存在直到你的 ImageView 存在,所以合成是从 ImageView 到 Tag 而不是相反,简单来说 Java tag 只是一个 class View class 的级别 属性,其中 ImageView 或 AppCompatImageView 在层次结构中的某处扩展。因此,如果 ImageView 存在,相同的 ImageView 对象,那么您的相同标签将存在。