问题
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?
回答1:
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
回答2:
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 )
回答3:
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/
回答4:
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.
来源:https://stackoverflow.com/questions/38328894/how-does-facebook-or-instagram-app-retain-images-or-data-after-entering-the-app