How does facebook or instagram app retain images or data after entering the app with no internet connection?
Asked Answered
A

4

5

In Facebook app, for example, I login with my internet connection. Then I close the app, turn off the internet and close all my system tabs. Then even though my internet connection is off, I see the images and data that had been previously loaded still retained.

How does Facebook app do that? What should I do if wanted to implement such a feature in my Android app?

Anchovy answered 12/7, 2016 at 12:27 Comment(7)
The images are cached and saved to disk, then shown instead of always requested by a network request.Afterclap
Possible duplicate of Load images from disk cache with Picasso if offlinePushkin
@HiteshSahu my friend its not duplicate completely because he wants to cache/store data too, not only images.Sopher
have you got your answer ? because from below answers they all are talking about image caching only . no one mentioned data part in that .Yettayetti
Hey Shababb have u got any answer ? if yes please let me know.Faunie
@TusharLathiya I feel like there are many solutions to how Facebook and Instagram cache images. Picasso and Glide are two libraries that automatically cache images. Retrofit with OkHttp can be used to cache responses and you can always make a custom caching mechanism with local db using RoomAnchovy
Thanks for reply @ShababbKarimFaunie
C
3

i use 'Picasso' Library for caching, loading... images from internet :

http://square.github.io/picasso/

Automatic memory and disk caching

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

for data, you can store data using shared preferences for small stuff or a local database like sqlite

Candie answered 12/7, 2016 at 12:34 Comment(0)
A
1

You can cache these images ( saving them locally ) - there are multiple ways to do so. Some image loading libraries are doing this - or you can do this on the transport-layer ( e.g. with okhttp )

Actinia answered 12/7, 2016 at 12:30 Comment(1)
Could you please give me a link or a hint on how cache these images?Anchovy
T
1

There are so many image caching libraries. Such as Picasso,Volley,Universal image loader and so on.Refer these links.

https://github.com/nostra13/Android-Universal-Image-Loader

https://developer.android.com/training/volley/request.html

http://square.github.io/picasso/

Tamra answered 12/7, 2016 at 12:41 Comment(0)
P
0

Simply they have disk cache, if you open Facebook Android App and go Open Source Libraries part you will see they using DiskLruCache . And if you check Facebook App size in Applications its growing everyday. Also you can use mobile database like Sqlite or Realm etc.

Poon answered 12/7, 2016 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.