Title: How to prevent the foreground service is killed by mobile cleaner
Tags: android;android-studio;kotlin;android-service;mobile-application
Question: I had create a foreground  application in Android 12 that is working fine when tha app is remove from recent task. when I had using my mobile cleaner the foreground service also killed.
How to prevent the foreground service killed by mobile cleaner
Comment: Yeah the best you can do is try to warn people if your app is something that could be affected by this stuff (it's usually a problem when the app's supposed to run in the background). It's not just cleaner/"green" apps, some manufacturers heavily restrict what apps can do on their devices, and you need to explicitly opt apps out of these restrictions. https://dontkillmyapp.com is a typical resource devs point users to, but that's not about cleaner apps. Maybe you can detect if your app was killed (didn't complete properly) and display a warning / info links next time they open it?

Comment: The issue looks like a copy of https://stackoverflow.com/questions/34222943/how-to-restart-service-after-the-app-is-killed-from-recent-tasks

Comment: People use these kinds of ridiculous apps because they *want* to force all apps to close. Not much you can do about that except try to educate customers about why these apps make their phones perform worse, not better.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:08/04/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-studio><kotlin><android-service><mobile-application>', 'Title': 'How to prevent the foreground service is killed by mobile cleaner', 'ViewCount': 87, 'id': 73240625, 'user_AboutMe': None, 'user_AccountId': 25980076.0, 'user_DisplayName': 'Prasath Roman', 'user_Reputation': 1.0, 'user_Views': 1.0, 'user_id': 19693951.0}}