txusballesteros / bubbles-for-android

Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.
Apache License 2.0
1.48k stars 281 forks source link

Android OS kills the service on back press or after small period of time #7

Open n0m0r3pa1n opened 9 years ago

n0m0r3pa1n commented 9 years ago

The bubble stays no more than 5 minutes and after that the system kills the service and it recycles the bubbles. This happens on Nexus 4 with Android Lollipop 5.1.1

pierrebrtr commented 9 years ago

This happens to me if i press the back button ! i'm on a nexus 5 with Cm 12.1

n0m0r3pa1n commented 9 years ago

I commented the code in the onUnbind method of the BubblesService and made the service extend IntentService and now I think that everything is OK. Also the back button is working. Is that a fix?

public BubblesService() {
        super("BubblesService");
    }
...
public boolean onUnbind(Intent intent) {
//        for (BubbleLayout bubble : bubbles) {
//            recycleBubble(bubble);
//        }
//        bubbles.clear();
        return super.onUnbind(intent);
    }
...
@Override
    protected void onHandleIntent(Intent intent) {

    }

In the BubblesManager in the recycle() method comment the:

//context.unbindService(bubbleServiceConnection);

This will keep the connection alive and the service won't be recycled.

txusballesteros commented 9 years ago

@n0m0r3pa1n This code is a great approach to your goals, but IMHO not is a fix for all.

dshatov commented 9 years ago

There is solution: http://stackoverflow.com/a/2476962

n0m0r3pa1n commented 9 years ago

Sooner or later the service is killed again. I tried this method. I see that Facebook Messenger is using startForegroundService for its chat bubbles. I read that it has longer life so it may be the solution.

ralphilius commented 9 years ago

@n0m0r3pa1n Thanks for pointing out. That would be an appropriate approach to this issue.