需要Firebase实时数据库持久性说明 [英] Firebase Realtime Database persistance clarification needed

查看:179
本文介绍了需要Firebase实时数据库持久性说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于启用了Firebase实时数据库持久性的Android客户端,假设没有对数据库进行任何更改,是否每次关闭并重新打开该应用程序时都不会有Firebase下载?

b
$ b

此外,启用持久性后,每次重新打开应用程序时,Firebase是否只会下载更改?

$ b


通过启用持久性,任何数据即使在我们重新启动应用程序的情况下,我们在线同步的数据仍然是
,并且可以脱机使用。
这意味着我们的应用程序将像在线使用存储在缓存中的本地数据
一样工作。监听器回调将继续触发
本地更新。

在Android上启用离线功能



一行代码,而且我已经将离线功能集成到了我最近开发的所有项目中,它对我们的开发者来说就像是一个魅力,而不是让我们头痛。

$ b
然后,我通过Firebase控制台向数据库添加了一些字符串,并在重新启动应用程序时监视使用情况,并且可以看到显示器中的网络使用情况很少,将定义为只是下载我所做的更改到我的数据库,我的应用程序立即与变化同步。

For an Android client with Firebase Realtime Database persistence enabled, is it true that there will be no Firebase downloads each time I close and re-open the app, assuming there have been no changes to the database?

Furthermore, with persistence enabled, each time an app is re-opened, is it true that Firebase will only download the changes?

解决方案

Yes to both, if I may quote the documentation :

By enabling persistence, any data that we sync while online will be persisted to disk and available offline, even when we restart the app. This means our app will work as it would online using the local data stored in the cache. Listener callbacks will continue to fire for local updates.

Enabling Offline Capabilities on Android

It's just amazing you could do this with one line of code, and I've been integrating offline capabilities to all the projects I've been developing lately, it works like a charm and less headache for us developers.

EDIT:

Provided that disk persistence is enabled and it isn't the first launch of the app, I can confirm that Firebase does not re-download the whole database again. When I was first implementing the persistence storage.I was monitoring the network usage of my app using Android studio, in first launch I could see a considerable usage of network resources, then I restarted the app and there was no activity in the network usage monitor.

Then I added few Strings to the database via Firebase console and monitored the usage when I restart the app and I could see a small network usage in the monitor, which I would define as just downloading the changes I did to my database and my app was synced with the changes instantly.

这篇关于需要Firebase实时数据库持久性说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆