Firebase 在后台读取数据 Android [英] Firebase Read data in background Android

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

问题描述

无论如何我可以从firebase的实时数据库中读取数据并可以在未打开应用程序的情况下保存它,我正在使用Firebase.getInstance.goOnline();在网络连接发生变化时在代码中,以便它侦听数据.

Is there anyway that I can read the data from the real time database of firebase and can save it while the app is not opened, I am using Firebase.getInstance.goOnline(); in the code whenever Network connectivity changes so that it listens the data.

如果应用程序不在最近或未打开,我可以将数据写入数据库,但同样的,当应用程序未打开时我无法读取数据.有什么可能的方法吗?还是我采用了错误的方法?

I am able to write the data in the database if app is not in recents or is not opened but in the same way I am unable to read the data when app is not opened. Is there any possible way ? Or I am going for an wrong approach ?

我只是希望只要网络连接可用,它就会自动下载更新的数据.,以便稍后我可以看到离线的更新数据.

I just wants that whenever network connection will be available it will download the updated data automatically. , so that later on I can see the updated data being offline.

任何帮助将不胜感激.请.

Any help will be highly appreciated. Please.

推荐答案

Android 不保证您的应用进程在屏幕上不可见时是否正在运行.它可以被杀死,以支持对用户具有更高优先级的其他进程.因此,一般来说,假设您可以随时建立网络并不是一个好主意.

Android makes no guarantees about whether or not your app process is running when it's not visible on screen. It could be killed in favor of other processes that are a higher priority for the user. So, in general it's not a good idea to assume that you can do networking any time you want.

此外,较新的 Android 设备将进入打盹模式 帮助节省用户的电量.在这种情况下,您的应用肯定不会运行.

Also, newer Android devices will go into doze mode to help save the user's battery. In that case, your app will definitely not be running.

如果您想确保您的应用进程正在运行,您可以使用 JobSchedulerAlarmManager.或者,您可以使用 Firebase Cloud Messaging 从您的服务器 ping 您的应用.

If you want to ensure that your app process is running, you can schedule some time with JobScheduler or AlarmManager. Or you can ping your app from your server with Firebase Cloud Messaging.

这篇关于Firebase 在后台读取数据 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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