I want to put a lock icon to my app. How can I do that programmatically as in some social apps like in the following picture? I want to prevent the user from clearing my app from recent screens or task as it's using services in the background and Oppo, Mi and Lenovo kills it. I already tried it but it didn't work for me
startLockTask();
Firstly, that lock is not implemented by Whatsapp or any other social networking site. That lock is set by the user manually.
And what does that Lock do is whenever the user clears RAM, then all the applications that are locked will not be killed if that (app) is either in the foreground or background. So that's nothing to do with the code of that particular app.
Now, quoting this line: I want user to prevent from clearing my app from recent screens.
Users can still clear any of the locked apps manually. That means if they swipe any locked app, then that app will be cleared. That lock only prevents the clearing of app when the user taps on clear RAM.
All in all, You can't set that kind of lock programmatically in any of your apps.