在Android上使用Stheto查看本地Firebase数据库 [英] View local firebase database with Stheto on Android

查看:228
本文介绍了在Android上使用Stheto查看本地Firebase数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个Android应用,该应用使用Firebases实时数据库作为后端.我观察到,第一次获取节点的子节点会花费更长的时间,因此我认为Firebase使用本地数据库.但是,如果该应用程序被杀死(即使启用了持久性),本地文件似乎也会被删除.

I'm currently building an Android app which uses Firebases realtime database as it's backend. I observed, that getting the children of a node the first time takes longer so I assume, that Firebase uses a local database. However the local files seem to be deleted if the app is killed (even with persistence enabled).

我想使用Stetho检查本地数据库,但是我无法在chromes开发人员工具中显示的本地数据库中找到数据.

I wanted to inspect the local database using Stetho, but I can't find the data in the local databases displayed in chromes developer tools.

是否可以查看本地数据库的外观?即使应用程序被杀死,也有可能保留数据吗?

Is there a way to view how the local database looks like? And is there a possibility to keep the data even if the app is killed?

推荐答案

tl; dr:您可能还没有

tl;dr: you likely haven't enabled disk persistence.

当您的应用首次连接到Firebase时,会发生这种情况:

When your app first connects to Firebase, this happens:

  1. 首次获取数据时,Firebase会在客户端和服务器之间建立连接.这花费的时间取决于客户端和服务器之间的路径,但通常需要几秒钟.

  1. The first time you're retrieving data, Firebase sets up a connection between the client and the server. The time this takes depends on the path between the client and the server, but is usually multiple seconds.

如果使用身份验证,则此初始握手"还包括登录用户或刷新其令牌.

If you use authentication, then this initial "handshake" also includes signing the user in, or refreshing their token.

然后Firebase检索您请求的数据.花费的时间主要取决于您请求的数据量和客户端设备的带宽.

Then Firebase retrieves the data that you requested. The time this takes is mostly dependent on the amount of data you request and the bandwidth of the client device.

如果执行这些步骤,则第3步通常花费最少的时间.但是,当您请求其他数据时,Firebase客户端只需执行步骤3,因为它可以保持调用之间的连接和身份验证状态.

If these steps, step 3 often takes the least amount of time. Yet when you request additional data the Firebase client only has to take step 3, since it maintains its connection and authentication state between calls.

默认情况下,Firebase将您正在积极侦听的数据保留在内存中.如果为同一数据附加第二个侦听器,则该侦听器将从内存中获取数据的副本.因此,在这种情况下,读取是即时的,因为甚至不需要之前的第3步.

By default Firebase keeps the data that you're actively listening for in memory. If you attach a second listener for the same data, that listener gets a copy of the data from memory. So the read is instant in that case, since even step 3 from before isn't needed.

当您为特定数据分离所有侦听器时,Firebase会立即将其从内存中清除.因此,这意味着下次连接侦听器时,它将不得不重新读取数据(上面的第3步).

When you detach all listener for a specific piece of data, Firebase will flush it from memory immediately. So that means that next time you attach a listener, it will have to re-read the data (step 3 from above).

如果您启用磁盘持久性 ,Firebase客户端还会 将接收到的所有数据的副本存储到磁盘.这是所谓的MRU缓存,因此它仅包含最新数据,并且在应用程序重新启动之间持续存在.但这仅在您启用了持久性后才会发生.

If you enable disk persistence, the Firebase client will also store a copy of any data it receives to disk. This is a so-called MRU cache, so it only contains recent data, and it persists between restarts of your app. But this only happens if you've enabled persistence.

本地磁盘缓存是常规的sqlite数据库.如果您有兴趣将其用于调试目的,它(至少对我而言)位于/data/data/{applicationId}/{applicationId}_default中.这是一个sqlite数据库.但是该格式未记录在案,因此您需要自己找出其中的任何内容.

The local disk cache is a regular sqlite database. If you're interested in looking at it for debugging purposes, it (for me at least) lives in /data/data/{applicationId}/{applicationId}_default. It is a sqlite database. But the format is not documented, so you're on your own figuring out anything inside it.

另请参阅:

这篇关于在Android上使用Stheto查看本地Firebase数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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