Prevent android to recycle the app when app is backgrounded

MohamediAIJH-8327 261 Reputation points

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?

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 47,671 Reputation points Microsoft Vendor


    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