ricvalerio / foregroundappchecker

Foreground application detection library for android.
Apache License 2.0
191 stars 50 forks source link

Service killed with FG Checker callbacks? #11

Closed RuchirB closed 5 years ago

RuchirB commented 6 years ago

I am using this library to allow the user to monitor his/her usage on each app of their phone. For that reason, I've set up callbacks in a continuous service; however, the service is killed on its own.

https://stackoverflow.com/questions/51460417/why-does-android-keep-killing-my-service

I have posted some more details on a stack overflow question, but it seems as though the fgchecker process is getting killed even though it has calbacks to the service. Any thoughts?

ricvalerio commented 6 years ago

Hello,

Have you tried with the sample? Does it also get killed?

Could you describe a bit more how you are doing this? Do you use only one service, or do you have separate services, like for example one for the fgchecker and another for your own? Whichever is the service that has the AppChecker running continuously, you should use startForeground on that service to make it less likely to get killed.

ricvalerio commented 5 years ago

@RuchirB,

Also make sure your service in in Foreground mode, with a sticky notification, which helps prevent the OS from killing your service. Beyond that, you would have to resort to other mechanisms to try to make sure your service stays alive.

filipesperandio commented 5 years ago

From my experience, foreground service is all you should need as @ricvalerio pointed out.

ricvalerio commented 5 years ago

Upon looking at the stackoverflow link, it appears the issue has been solved.

Closing this issue