how to avoid lowmemorykiller closing my service

1.1k Views Asked by At

I am building a service for android 9 and found that in some situations it is closed by the android system

When looking at the logcat it seems to be killed by the lowmemorykiller

I have two questions:

  1. in android manifest i set an intent-filter android:priority="1000", should that solve the issue?
  2. what is the suggested stress test to simulate low memory conditions for testing? A source code would be very helpful.
1

There are 1 best solutions below

1
Ivan Ardelian On
  1. You need to use android:priority="999" or less.

SYSTEM_HIGH_PRIORITY Constant Value: 1000
Applications should never use filters with this or higher priorities.

  1. adb shell am send-trim-memory com.example.app MODERATE

[HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]

(Note that this command is available for devices with API >= 21)

Also I had a lot of situations when I needed "unstoppable" service, so I wrote my library. You can try it here: https://github.com/iardelian/Revive-S