I have an app designed for a tablet in a workplace setting where a number of people will use the camera as part of their routine. While it's appropriate and necessary for a supervisor to leave the app, it should be difficult for other people to accidentally do so. However, a long press of the home key is pretty easy to do accidentally. I've done it myself. That brings up a list of recent tasks; the user can tap any one of them and they're lost, since some of them aren't as sophisticated as your average smartphone owner.
Programmatically you can retrieve this list via getRecentTasks. My question is how I can remove all but the most recent task (mine) from that list, reduce the length to just one element, or change the listed tasks to point back at my application. I know this is possible: Toddler Lock does it.
My first attempt was to modify the intents returned, in hopes they were passed by reference. No such luck. Any other ideas?
(I'm not talking about a short press of the home key. I already figured that one out, partially based on things found here.)
Credit goes to the author of Toddler Lock, with whom I spoke about the issue. Errors introduced are entirely mine.
Create within your manifest a disabled activity with affinity equal to the empty string. In your program, enable it and then start it up using an intent flagged FLAG_ACTIVITY_NEW_TASK. It will show up in the recent activities. Disable the task and it disappears from the display.
Make enough of these and you flood the recent activities display. If it has a way to go back more activities than you have dummy activities the user will be able to get out of your program.
Make sure you disable the tasks when you exit, and make sure that if you select one of those tasks from recent activities your program does something reasonable.
Here's an example of two of the tasks in my manifest:
You can't do this from an application. You would need to build a custom system image with the behavior you want.