My app gets the data while its connected to internet but I want the app to get the data offline from cache. Please help I'm new to Firebase.
Simply activate offline persistens
as specified in the official documentation :
Firebase applications work even if your app temporarily loses its network connection. You can enable disk persistence with just one line of code:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
You try this it will help for you
First create an application class
public class BaseApp extends Application {
@Override
public void onCreate() {
super.onCreate();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Picasso.Builder builder = new Picasso.Builder(this);
builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));
Picasso build = builder.build();
build.setIndicatorsEnabled(false);
build.setLoggingEnabled(true);
Picasso.setSingletonInstance(build);
}
}
Keeping the data fresh using the below line
DatabaseReference mRootRef =FirebaseDatabase.getInstance().getReference("images");
mRootRef.keepSynced(true);
More details on persistence and syncing can be read here in the Firebase documentation: https://firebase.google.com/docs/database/android/offline-capabilities
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.