如何保持FirebaseDatabase连接始终在线?至少几个小时 [英] How to keep FirebaseDatabase connection always online ? At least for few hours

查看:82
本文介绍了如何保持FirebaseDatabase连接始终在线?至少几个小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我保持Firebase数据库连接始终在线吗?我一直在从事类似于UBER应用程序的项目.我只是想让客户即使在后台运行应用程序时也能够看到驱动程序. 为此,我必须保持Firebase数据库和驱动程序应用程序的连接,即FirebaseDatabase.getInstance().goOnline().总是 !!至少几个小时. 故事就像有两个应用程序,我们可以在其中看到彼此的位置 在地图片段上,我只想做一个第一个应用程序是否在后台运行的操作,即使那样,第二个应用程序也应该能够看到第一个应用程序的位置(第一个标记).就我而言,它仅持续几分钟. 我已经进行了很多研究,并且了解了哪些服务可以在后台运行,但是我怀疑该服务如何使我的应用活动与FirebaseDatabase连接. 就像是,如果服务正在运行并且与数据库连接,那么我的应用程序活动也已连接?即FirebaseDatabase.getInstance().goOnline()== true ??

Can some body help me in keeping Firebase database connection always online? I have been working on a project which is similar to UBER app. I just want to make customer able to see driver even when driver's app is working in background. For that I have to keep Firebase Database and driver app connected i.e FirebaseDatabase.getInstance().goOnline(). always !! At least for few hours. The story is like there are two apps where we can see each others locations on map fragment and i just want to do like if first one's app is working in background , even then the second one should be able to see the location (marker of first) of first one. In my case it lasts for only few minutes. I have researched a lot and i got to know about Services which work in background but my doubt is how can that Services can make my app Activities connected to FirebaseDatabase. Is it like, if services are working and connected with database, then my app Activities are also connected ? i.e FirebaseDatabase.getInstance().goOnline() == true ??

需要一些代码和帮助!请!!

Need some codes and help ! please!!

推荐答案

如果您的应用很长一段时间处于后台,您需要知道Android(操作系统)可能会杀死您的应用程序,而更多重要的应用程序.当在前台不再可见时,Android可能还会阻止您的进程联网.这是正常现象,因为一般的兴趣是防止行为不良的应用程序消耗过多的资源.

If your app will be in backgroud for a long period of time, you need to know that Android (Operating System) may kill your app's process in favor of more important apps. Android may also stop your process from networking when it's not longer visible in the foreground. This is the normal bahaviour since the general interest is for preventing poorly behaved apps from consuming too many resources.

如果您的应用在用户不再使用时需要继续联网,则必须启动foreground service,这还要求您向用户显示通知,以向用户表明您的应用仍在运行.这是因为用户应该意识到该应用程序将消耗比预期更多的资源.

If your app needs to continue networking when the user is no longer using it, you'll have to start a foreground service, which also requires that you show a notification to the user that indicates to the user, that your app is still running. This is nedded because the user should be aware that the app will consume more resources than expected.

这篇关于如何保持FirebaseDatabase连接始终在线?至少几个小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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