Today’s #AndroidDev #Protip is from +Katherine Kuan on screen pinning.
In Android 5.0 Lollipop, we’ve introduced the screen pinning feature, which temporarily restricts users from leaving a task or getting interrupted by notifications. Here are two ways to take advantage of it.1. As a user, you may pin a screen before you hand off your device.
Pinning a screen keeps the device locked to the current task. It minimizes the chance of accidentally hitting a system nav button to inadvertently leave the app. However, this feature is not meant to enforce secure lockdown of the device because using the system UI, a user can still exit screen pinning mode. Any Lollipop user can enable the screen pinning feature by going to Settings app > Security > Screen pinning.
Next open the desired app, and then open the Overview space (recents). Pin the screen by touching the circular pin icon. See images below. 2. As a developer, you may prompt the user to pin a screen from inside your app.
You can extend your app (if it’s an immersive game for example) with the screen pinning API. You can surface a way for users to start and stop screen pinning mode in your app, without requiring them to go to the Overview space. Within the Activity code, call startLockTask()
. A dialog prompt appears to the user before the mode starts. It’s possible to detect that the mode has been started when isInLockTaskMode()
 is true. Afterwards, the user can exit this mode via the system UI or by clicking on app UI that calls stopLockTask()
. A secure screen lock may be presented upon unpinning, depending on the selected behavior in the dialog prompt (and the device’s current security settings).
Note that screen pinning is a lock on the task
, and not a lock on the app or the activity. In this mode, you can’t create or switch to a new task (even in the same app). Follow best practices on using tasks in your app. 
Check out the developer site for more details on the behavior of the screen pinning mode.