Firebase connection is lost and never come back

Hi there ! Thanks everyone for your works and help !

I’m having an issue with firebase and ionic : I installed my app on my android device (Samsung Galaxy S4) and everything worked fine but after a small amount of time I’m loosing connection to firebase and the only way to get it back is to clear app’s Data from app’s manager ! Quite weird isn’t it ?

here is my script :

.factory("Items", function($firebaseArray) {
var itemsRef = new Firebase("");
return $firebaseArray(itemsRef);

And in my controller :

.controller('MainCtrl', function($scope, $ionicPopup, Items) {
`$scope.items= Items;`

And in the html :


First time I’m running the app it will display all the data from Firebase without any problem and after sometimes when I restarted the app it will not works anymore.

Cordova CLI: 5.4.1
Ionic Version: 1.2.0-nightly-1823
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
OS: Windows 8.1
Node Version: v5.1.0

Please help me I’m out of option ! Thank you all !

Please help me I spent hours and hours on this problem. I tried someone else apps but the problem remain the same so that’s not something in my script.

It seems that local data on local storage are corrupt. But why and how I do not understand. Anyone ? Please ! :slightly_smiling:

I also had problems with androin and local storage.
I googled and found out that there are problems in Android 5.x i guess. Didnt touched the problem for a while.

Maybe you isolate the problem with a simple local storage test?

How did you realize that the data are corrupt?

Hi @JuliusSakata,

You are not alone. This problem has been bugging me from the very beginning of using Firebase.
To the point it made me question this service.

Yes, leaving the app in the background for a while will result in lost connection, that you won’t be able to get back as far as I know. ( to people who might read this, yes I already implemented a presence system, with the onDisconnect() function, but once connection is lost, although the onDisconnect() does update your base one last time, any further attempt to reach out to firebase will fail. Even using Firebase.goOnline() )

I reached out to Firebase team regarding that matter, hopefully they will have a solution.

Yeah that was the idea. I found some stuff on a forum where someone had the same problem. Then I started making some test on the data. So basically when you remove local data on the mobile the app works without any problem.

Hi @pierro

So it seems that firebase with ionic is useless since it doesn’t work in every single android system. It’s a shame but no other choice than using our old Mysql + Api combo…

Actually, I’m approaching the issue differently now.

When the sockets is killed forcefully by firebase when app is in background too long, it never comes back. That we know.

However, when YOU choose to manually kill it with Firebase.goOffline(), then using Firebase.goOnline() will always bring it up again.

I’m using Firebase.goOffline() every time the user pause the app (meaning it goes background), and Firebase.goOnline() everytime he resumes.

And so far, it’s working pretty well. Even hours after leaving the app, when coming back the Firebase.goOnline() does its job and brings back the connection. :slightly_smiling:

Let me know if it works for you as well!

1 Like

Thank you for your answer and for the tips.

How can you detect the app is paused ?

Thank you !

Very simple!

Here is my code in app.js :slightly_smiling:

document.addEventListener("resume", function () {
   document.addEventListener("pause", function () {

Thank you ! I will try this ! You add this code in your main controller or in run() function ? It’s the first time I see “document.addEventListener” in Ionic :slight_smile:

You can do the same with ionicPlatform on pause / resume. Look into ionicplatform.

I’m just more comfortable with this, although I guess it’s exactly the same…

I add this on Ionicplatform ready in my app.js, in run() function. :slightly_smiling:

unfortunately it doesn’t work :frowning:

How do you know it doesn’t work?

Is the connect / disconnect function called at least? put a console.log in the pause / resume function to be sure.

What does the log say?
Also, did you set up a presence system?

This is a great to test. I see my user on the presence node getting removed as soon as I pause, and back when I resume.

I did a very simple test : on the first page of my app I display some data from firebase. It worked then after a certain time (which is absolutely random) it doesn’t work anymore I restart the application and the data that were displayed just a while ago does not work anymore.

I didn’t try anything to see if the pause / resume function are called I will try this first !

Hi everyone, I read this post carefully because i’m expecting the same problems.

I did the test with “pause” and “resume” passing through addEventListener and also with $ionicPlatform.on , but none of them worked when I disconnect the network with the app running in background.

Some of you found a solution to solve this problem ?

(Running on Android 5.X, I’m going to test my app on older android version)

I’m having the same problem on iOS (when viewing my app with Ionic View). Will try the on and off when user pauses, hope this will do the trick!

I gave up with firebase. After many tries and fails Firebase seems way too unstable (or way too complicated) to be serious. I used some old mysql/php API and it work like a charm.

Well it’s just a shame. In fact I found it very easy to set up and make it all work. Spend about 80 hours this week on building an app (had a week off), and it does everything I want it to do. This is really the only issue I’m dealing with right now. Did try to do the ‘online/offline’ thing @pierro mentioned, but it didn’t fixed the issue for me. Now I’m really doubting on either I should continue developing my app with Firebase… I can think of some workaround for this issue, but I really want a fix for it… :frowning:

It’s a shame yeah. But after almost one year after my first post here you are… I choose not to spend more time with something that barely worked. I needed 100%.

I totally agree… I guess I still have some hopes or somebody has the magic fix. It’s funny though it seems like not a lot of people dealing with this issue (not that many google results on this)… Thanks for your time, keep you updated if I make any progress! Happy new year :slight_smile: