How to avoid downloading image from firebase if i

2020-05-03 11:15发布

I am trying to store image from firebase database and named it FirebaseuniqUserID.jpeg.(like buwkgefuikbuifbkc8gfybfy.jpeg). And user can change image anytime. For getting image link from firebase realtime database i used addListenerForSingleValueEvent.

FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseuniqUserID).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        //here i am downloading image//
        //and named it FirebaseuniqUserID.jpeg
    }

Now the problem is this when this listener is called every time image is download. But now i want avoid downloading if current user has latest updated image of user in firebase to reduce firebase downloaded data.

2条回答
别忘想泡老子
2楼-- · 2020-05-03 11:47

You can use two different options, first is Glide and 2nd is that, you can save image downloading status in your local database file or SharePreferences. But image cache is the best solution.

查看更多
家丑人穷心不美
3楼-- · 2020-05-03 11:56

I want avoid downloading if current user has latest updated image of user in Firebase

To solve this, I definitely recommend you to use an image loading and caching library. For Android we have Glide:

Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

查看更多
登录 后发表回答