Is there any method through which i can make my Firebase
listeners active, even when the application is not running?
I need to add listeners at runtime, without using service.
Please help me out.
Is there any method through which i can make my Firebase
listeners active, even when the application is not running?
I need to add listeners at runtime, without using service.
Please help me out.
In your case, to achieve this, simply don't remove the listener.
But remember, if you don't remove a listener when it's no longer needed, it will continue to receive changes that occur at the location where it's listening. So every time you add a listener without removing it, all the prior listeners will all still receive results. I can only imagine that repeating this many times will quickly consume the available network bandwidth on a device with a mobile data connection and obviously will cause slowness.
Here is how to remove the listener according to the life-cycle of your activity.
All the Firebase instances, whatever they are, are only in-memory instances inside your process, same goes for the listeners you add to them.
When your application's process is killed/stopped for whatever reason, all those listeners and instances will be garbage collected and will no longer be alive in memory, therefore will not trigger any updates.
Doesn't matter if you remove listeners or not, if the process hosting all those is gone.
If you want something to live in the background even if your app is not running. You should consider using a Service
.
Or better explaining your use case would make it easier to help you.
There are not many -or any- use cases that will require realtime update ALL the time, every second of every hour of everyday.