Android app with Push Notifications and Background Process are killed in some cases

We have an Android app that gets Push Notifications via FCM and Background Service that is working even when the app is not active. We are experiencing some issues with Android Operating System killing the background service and in other cases automatically closing the Notifications for our app. ( By automatically turning off Notifications for our app ).

Our first suspect was Doze mode introduced in Android 6 and later but we are using AlarmManager with setAndAllowWhileIdle() for scheduling the process and this should be enough for firing even during the doze mode as documented here. In addition we found out that in certain devices like Xiaomi and Huawei devices there is a known issue of Push Notifications not working and background services not running and we handle it. But the issue still remains in different device types and Android Versions.

Any ideas for the reason this can happen? Thanks!

Upvotes: 3

Views: 489

Answers (1)

dustblue
dustblue

Reputation: 551

The System sometimes kills the service when the memory is low.

In your background Service, override onStartCommand() and return START_STICKY as the result.

It will tell the system that even if it will want to kill your service due to low memory, it should re-create it as soon as memory will be back to normal.

Upvotes: 1

Related Questions