【问题标题】:Image is not updating in app using picasso使用毕加索的应用程序中的图像未更新
【发布时间】:2018-12-23 06:39:24
【问题描述】:

当我尝试在我的应用中更新图像时,它不是在更新,而是在 Firebase 存储更新中 我习惯了

Picasso.get().load(image).placeholder(R.drawable.profile).into(profileImage);

我也试过

Picasso.with(SetupActivity.class).load(image).placeholder(R.drawable.profile).into(profileImage);

这些是我的依赖项

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'

    implementation 'de.hdodenhof:circleimageview:2.2.0'

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'

    implementation 'com.squareup.picasso:picasso:2.71828'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

【问题讨论】:

  • 你能告诉我们你的数据库结构,你从哪里得到这个 url 值 dataSnapshot.child("profileimage").getValue().toString();这可能是问题

标签: android firebase firebase-realtime-database firebase-storage picasso


【解决方案1】:

Picasso 确实会缓存图片,但如果您的图片有不同的 URI,它会下载它但之前的图片仍被缓存,您可以“无效”以删除之前的图片,然后加载最近的图片。

Picasso.with(bContext).invalidate(bFileURI); //invalidates files

如果您的结构是这样的,您使用相同的 URI 覆盖图像并且您根本不希望它缓存,那么就去

Picasso.with(bContext) .load(bImage_url) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.NO_CACHE) .placeholder(R.drawable.default_img) .into(bImageView);

(我宁愿无效,因为后者不是离线使用的好习惯)

由于您使用的是 Firebase,因此您也可以考虑这一点并将字节作为字符串保存在 SharePreference 中以供离线使用......仍然是不好的做法。

final long bOneMB = 1024 * 1024;                               //size 
userProfileImageRef.getBytes(bOneMB)                           //get byte
    .addOnSuccessListener(new OnSuccessListener<byte[]>() {       // add listener
        @Override
        public void onSuccess(byte[] bytes) {                     // called if successful
            Bitmap bBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
            profileImage.setImageBitmap(bBitmap);                // sets bitmap in image view
        }
    });

【讨论】:

  • 我试过这样 Picasso.get() .load(image) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.NO_CACHE) .placeholder(R.drawable.profile) .into(profileImage );但不工作
  • 兄弟有没有其他选择,不使用毕加索??
  • 你可以使用滑翔
  • 我试过像这样滑行 Glide.with(getApplicationContext()).load(image).placeholder(R.drawable.profile).into(profileImage);还是不行
  • 您也可以尝试失效... Glide 非常快,可以将图像保存在范围内,但它仍然会缓存。
【解决方案2】:

在毕加索中试试这个.memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE)

【讨论】:

    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多