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

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

问题描述

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

我能够写入数据在数据库中,如果应用程序是不在最近或不打开,但以同样的方式,我无法读取应用程序未打开时的数据。有没有可能的方法?或者我正在做一个错误的方法?

我只是希望只要网络连接可用,它就会自动下载更新的数据。 ,以便稍后我可以看到更新的数据处于脱机状态。



任何帮助将不胜感激。请不要在您的应用程序进程在屏幕上不可见的情况下执行任何操作。它可能会被牺牲,而有利于用户的更高优先级的其他进程。因此,一般来说,假设您可以随时随地进行联网并不是一个好主意。

此外,较新的Android设备将进入打盹模式来帮助保存用户的电池。在这种情况下,你的应用程序绝对不会运行。



如果你想确保你的应用程序正在运行,你可以安排一些时间 JobScheduler AlarmManager 。或者,您可以使用 Firebase云消息传递从服务器ping您的应用。

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 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.

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.

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天全站免登陆