- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个在 onCreate
调用它的 Android 服务:
FirebaseDatabase database = FirebaseDatabase.getInstance();
database.getReference(".info/connected").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Log.d(TAG, "connected: " + snapshot.getValue(Boolean.class));
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.w(TAG, "Failed to read value.", error.toException());
}
});
我注意到,当我进行一些切换 wifi 和蜂窝数据时,我最终会看到一条“已连接:false”消息,而没有看到“已连接:true”消息。除了 Firebase 实时数据库,我还在服务中运行 Firestore,此时 Firestore 已正确连接。
然后我触发 Android 服务运行这段代码:
FirebaseDatabase.getInstance().getReference("random/data").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
boolean connected = snapshot.getValue(Boolean.class);
Log.d(TAG, "random data: " + connected);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
// Failed to read value
Log.w(TAG, "cancelled system/online.", error.toException());
}
});
现在,我得到了一个成功的读取并且打印了“connected: true”。
这是怎么回事?为什么我需要从 firebase 读取 .info/connected
来触发?
最佳答案
Why do I need to read from firebase for
.info/connected
to trigger?
答案在 offical documentation 中:
Firebase Realtime Database provides a special location at
/.info/connected
which is updated every time the Firebase Realtime Database client's connection state changes.
/.info/connected
is a boolean value which is not synchronized between realtime database clients because the value is dependent on the state of the client. In other words, if one client reads/.info/connected
as false, this is no guarantee that a separate client will also read false.On Android, Firebase automatically manages connection state to reduce bandwidth and battery usage. When a client has no active listeners, no pending write or onDisconnect operations, and is not explicitly disconnected by the
goOffline
method, Firebase closes the connection after 60 seconds of inactivity.
因此在 Android 上,您还可以利用连接状态管理。因此,一旦您实现了上述解决方案,您将看到 SDK 以一种动态方式管理此问题,如果没有附加监听器并且没有使用 setValue()
进行写入操作,则连接会自动断开连接在最后 60 秒内在应用程序中,但是 ValueEventListners
的存在将覆盖它并确保与数据库的持续连接。您还可以查看此 post 中的答案.
还有一个post我建议您阅读以更好地理解。
关于java - Firebase 实时数据库 .info/connected False 当它应该是 True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53069484/
以下代码中的 alert(`${info} : ${pokemondetails[info]}\n`) 的含义是什么?有人可以用更简单的形式向我解释一下吗? let checkname = funct
C-x C-f blah.info 以基本模式打开文件。我使用了 apropos 并发现了 Info-mode,我认为它可能会从基本模式更改为 Info 模式,但这会引发 lisp 错误。 如何在 e
我想在另一个 Info.plist 键 (NSContactsUsageDescription) 的值中使用“Bundle 显示名称”(CFBundleDisplayName) 的值。 我尝试了以下方
我正在使用 Python 3.6.4。我第一次遇到 logger.setLevel(logging.INFO) 被忽略的问题,然后遇到了 this answer ,这让我感到困惑并引发了这个问题。 鉴
我是python新手 如果 logging.info() 足以进行日志记录,为什么我们必须使用 getLogger() 方法实例化一个记录器? 最佳答案 在没有名称的情况下调用 getLogger()
下面是来自源代码的示例代码:https://docs.python.org/3/howto/logging.html import logging logging.basicConfig(filena
我在网上阅读的所有内容都在谈论 Info.plist。当我创建项目时,XCode 为我创建了一个 [应用程序名称]-Info.plist 文件,它似乎与我在网上看到的示例 Info.plist 具有相
我定义了一个记录器实例如下: private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); 我有一个要记录的
我的应用程序因 Info.plist 文件中缺少用途字符串而被拒绝(特别是对于 NSMicrophoneUsageDescription 用法)。 这取决于 react-native-permissi
我正在 Windows 下使用 Python 3.4.2。就我而言, import logging logger = logging.getLogger('logger') logger.setLev
我的背景主要是使用 C 和 C++ 进行 Windows 编程。最近我也有机会使用一些嵌入式 Linux 系统,但我对此还是个新手。 现在我正在为 Openwrt 开发一个实用程序,它需要对正常操作期
所以我只是按照此处所述运行了 INFO 命令 http://redis.io/commands/info 但它只给我默认部分——比如 cpu 信息和其他 当我尝试添加 [section] 参数时 -
我正在尝试了解 QEMU 内存管理(使用 i386 guest ,没有 KVM)。 QEMU 监视器允许列出 CPU 寄存器信息( info registers )、USB 设备( info usb
我的包中有 package-info.java,Hibernate 需要它来实现某些功能(编程实体扫描)。 但是,mvn package 不会导致 package-info.class 在 class
我遇到了似乎很常见的错误,因为 Xcode 似乎找不到我的“Info.plist”文件。 我已经检查了这两个 StackOverflow 问题的答案( Could not read from Info
我一直在尝试阅读 XEP-0030 Service Discovery但发现该语言非常不透明。 我的问题很简单:disco#info 规范和 disco#items 规范有什么区别? 我的猜测是 di
这个问题已经有答案了: String concatenation performance in Log4j (3 个回答) 已关闭 4 年前。 之前我通常使用log.info(“dsasdds ” +
我从 Erlang 文档中看到 supervisor:start_child 可以返回两个不同的非错误结果:{ok, Child} 和 {ok, Child, Info}。这个信息在哪里设置? sim
我使用的是 Crystal 0.25.0,File.info(string).symlink? 在以下示例中应返回 true 时返回 false: `mkdir -p /tmp/delete` Di
对于属性: Persist Security Info=true 和 Persist Security Info=false 你能告诉我它们之间有什么区别吗,如果我不把它放在我的连接中会发生什么? c
我是一名优秀的程序员,十分优秀!