How to avoid downloading image from firebase if i have already downloaded previously?

别来无恙 提交于 2020-01-22 02:32:10

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/58581858/how-to-avoid-downloading-image-from-firebase-if-i-have-already-downloaded-previo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!