Search code examples
androidrecordrecycle

How to keep My Application(record screen)alive when back to background in android phone?


I write a record screen applicatioin,when I press the start button, begin to record screen and call moveTaskToBack(true);

when I don't do heavy task ,the record screen work ok, when I do some heavy task,the record screen application recycle by android,

what can I do to keep my record screen Application alive when I do heavy task in the foreground?


Solution

  • It is not possible to block the Android recycling mechanism. If the system needs resources, it will kill the components of the non-foreground processes.

    What you can do is move the work to a Service and use as few resources as possible. Then launch this Service as a foreground service to ensure it will not be first in line for recycling.

    But you can never be 100% sure it will not be killed, because this depends on many factors, such as device specs and system code modifications (which are very common on Android devices.