首页 \ 问答 \ Kotlin - 如何使用onCompleteListener从Firestore获取数据?(Kotlin - How to do onCompleteListener to get data From Firestore?)

Kotlin - 如何使用onCompleteListener从Firestore获取数据?(Kotlin - How to do onCompleteListener to get data From Firestore?)

我有问题从Firestore获取数据,在JavaCode中我们可以这样做:

DocumentReference docRef = db.collection("cities").document("SF");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
        if (task.isSuccessful()) {
            DocumentSnapshot document = task.getResult();
            if (document != null) {
                Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData());
            } else {
                Log.d(TAG, "No such document");
            }
        } else {
            Log.d(TAG, "get failed with ", task.getException());
        }
    }
});

但在Kotlin,当我尝试覆盖onComplete函数时,它不可用。 那么,我怎么能得到“任务”?


I have a problem to Get data From Firestore, in Java code we can do this :

DocumentReference docRef = db.collection("cities").document("SF");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
        if (task.isSuccessful()) {
            DocumentSnapshot document = task.getResult();
            if (document != null) {
                Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData());
            } else {
                Log.d(TAG, "No such document");
            }
        } else {
            Log.d(TAG, "get failed with ", task.getException());
        }
    }
});

but in Kotlin, when I try to override the onComplete function, it's unavailable. so, how I can get the "task"?


原文:https://stackoverflow.com/questions/47214368
更新时间:2024-02-02 18:02

最满意答案

其中一个网卡出现故障。 我交换了网卡,它工作正常。 不知道为什么它以这种方式出现,但至少我找到了解决方案。


One of the NICs was faulty. I swapped the NIC and it worked fine. Not sure why it presented itself in this one way but at least I found the solution.

相关问答

更多
  • 在您的WSServerProtocol类中,在onMessage线程中: def onMessage(self, msg, binary): self.sendMessage(msg) in your WSServerProtocol class, in the onMessage thread : def onMessage(self, msg, binary): self.sendMessage(msg)
  • FiddlerCore是HTTP / 1.1协议的完整实现,直接在TCP / IP套接字上编写。 因此,它不会受到更高级别WebRequest类固有的限制(代价是我必须自己完全实现协议)。 I actually decided to chunk the data again each time I read in to the buffer from the responsestream (only if the response header is indicating a chunked respons ...
  • 其中一个网卡出现故障。 我交换了网卡,它工作正常。 不知道为什么它以这种方式出现,但至少我找到了解决方案。 One of the NICs was faulty. I swapped the NIC and it worked fine. Not sure why it presented itself in this one way but at least I found the solution.
  • 在目前的WCF 3.5中,你必须自己做这件事 - 参见优秀的两部分文章 构建WCF路由器,第1部分 构建一个WCF路由器,第2部分 Michele Leroux Bustamante。 随着WCF 4--与.NET 4一起发布,大概在2010年3月 - 事情会变得更容易,因为WCF 4已经包含了一个基础的“RoutingService”类 - 请参阅Ron Jacobs关于此主题的Endpoint.TV视频采访 。 渣子 In current WCF 3.5, you have to do this you ...
  • 当我们知道B准备好接收数据时,是否可以只读取套接字A? 当然:在套接字A和B上使用select.select (如果它返回说只有其中一个已准备就绪,在另一个套接字上使用它),并且只有当你知道它们都准备就绪时才从A读取并写入B. 例如: import select def fromAtoB(A, B): r, w = select.select([A], [B], []) if not r: select.select([A], [], []) elif not w: select. ...
  • 尝试将--skip-ssl指定为mysql客户端的选项。 我们正在修复此问题,并且应该在不久的将来推出。 发生这种情况的原因是我们拒绝通过请求MySQL SSL的代理连接。 代理和Cloud SQL之间的连接已经通过SSL完成,因此不需要在MySQL级别使用SSL。 Try specifying --skip-ssl as an option to your mysql client. We have a fix for this in progress and should be rolled out i ...
  • tcp-client-server-multiplex显示了一种异步代理请求/回复方案的机制; 您需要数据中的某些内容才能将回复与请求相关联。 它使用聚合器来做到这一点。 使用自述文件中引用的更简单的tcp-client-server示例,使用网关并且框架可以处理相关性(但它不会处理高容量,除非您在出站端使用CachingClientConnectionFactory (这实际上是您的如果您无法添加一些与回复相关的数据,则只有选项。 如果您只谈论单向消息传递,那么显然不需要关联(并且您在第一个示例中不需要聚 ...
  • 这听起来像是你想要穿线的缘故。 通过添加额外的线程究竟会解决什么问题? 鉴于异步模型回调到ThreadPool,你已经免费获得“线程化”。 你为什么想要更多? 您可以愉快地在读取操作的异步回调中从一个流复制到另一个流。 如果你也使用async进行编写,那么它不会对ThreadPool造成任何重大负担,而IMO的工作最好留在那里。 您是否考虑过使用async / await? 如果它是一个选项,那么它将使您的代码在大脑上的几度嵌套更轻。 It sounds like you want threading fo ...
  • 编辑 :该错误已在aiosmtpd 1.0b1中修复,因此升级应解决此问题。 在aiosmtpd 1.0a4中,Proxy.handle_DATA中的未捕获异常(使用data作为str而不是字节)会导致asyncio任务停止,但异常永远不会传播。 如果你升级到1.0a5,你将得到正确打印的异常:“错误:(TypeError)不能在字节类对象上使用字符串模式”。 问题是,从1.0a5开始,aiosmtpd中的Proxy设计用于在aiosmtpd.smtp.SMTP对象上设置decode_data=True的C ...
  • Python文档中的示例提供了实现客户端 - 服务器系统的基本背景。 但是,在两者之间添加代理需要对示例代码进行一些应用。 客户端 - 代理 - 服务器系统的骨架模型 客户 客户应该做以下事情: 阅读将要发送的文件 open() , fp.read()等 创建套接字并建立与代理的TCP连接 socket.socket() , proxysock.connect()与SOCK_STREAM 将存储在步骤1中的变量中的文件数据发送到代理 proxysock.sendall() 等待答案 proxysock.re ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)