0

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

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193

1 Answers1

1

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.

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Hey thanks for your reply. I just want to run the Firebase messaging services for longer period . Any help will be appreciated . – Praful Buyakar Jul 21 '18 at 14:14
  • You should make your own attempt given the informations in the answer and if something else comes up, post another fresh question so me or other users can help you. – Alex Mamo Jul 21 '18 at 17:13
  • Do you think my answer helped you? – Alex Mamo Jul 21 '18 at 17:13
  • Ya helped , another question , I am using data messages where we can send messages even when the app is killed or in background or in foreground . – Praful Buyakar Jul 21 '18 at 22:22
  • But in my case sometimes my app does not get those messages . I am sending messages from app to app. Sometimes the app get messages even when it is killed or removed from background but again , sometimes it wont. I want it to be absolute. I will post this again in better way .But iam waiting for your reply. – Praful Buyakar Jul 21 '18 at 22:29
  • https://stackoverflow.com/q/51460652/8825673 – Praful Buyakar Jul 21 '18 at 22:55
  • That's the right thing to do, to ask another question. I'll take a look and if I'll know the answer, I'll write it to you. – Alex Mamo Jul 22 '18 at 09:01
  • please check stackoverflow.com/q/51460652/8825673 – Praful Buyakar Jul 22 '18 at 09:54
  • I'll take a look and if I'll know the answer, I'll write it to you. – Alex Mamo Jul 22 '18 at 09:56
  • @AlexMamo Do you think the 'Foreground Service' is still the best option here after the 'Background Execution Limits' -> https://developer.android.com/about/versions/oreo/background ? – MrVasilev Nov 01 '18 at 09:15
  • @MrVasilev Yes, I think so. If you need more details about that, please post another fresh question so me or other users can help you. – Alex Mamo Nov 01 '18 at 09:17
  • @AlexMamo Thank you. First will make a small research about Foreground Service and than maybe will ask. Thanks again – MrVasilev Nov 01 '18 at 09:24
  • @MrVasilev You're welcome! – Alex Mamo Nov 01 '18 at 09:27