Prevent android to recycle the app when app is backgrounded

Anonymous
2022-11-16T13:19:47.507+00:00

If I change app to another one and go back, everything is preserved, scroll position, loaded page, everything.
But if I spend some time on other apps, and then go back, the app loads again because android recycled the memory.
Since this app is meant to be switching apps looking for information. Is there a way to ask android to prevent that?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,364 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2022-11-17T05:34:05.073+00:00

    Hello,

    You can create a foreground service to prevent applications closed. Foreground Services - Xamarin | Microsoft Learn

    Please note: Foreground services  |  Android Developers
    Apps that target Android 9 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission.
    Android 12 (API level 31) or higher can't start foreground services while running in the background, you need to start the foreground service in the foreground.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.