androidkioskandroid-screen-pinning

Activity.startLockTask() from one Activity to another Activity


I am using Activity.startLockTask() and have noticed that if I pin the screen in Activity A, I am unable to transition to Activity B. It seems like I have to startLockTask() and then stopLockTask() and then startLockTask() again on Activity B.

Is there a way a better way of doing handling this so that I can pin the entire app, regardless of what Activity I am on?

This is how I pin the app:

// start lock task mode if it's not already active
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// ActivityManager.getLockTaskModeState api is not available in pre-M
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    if (!am.isInLockTaskMode()) {
        startLockTask();
    }
} else {
    if (am.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_NONE) {
        startLockTask();
    }
}

This is how I am stop pinning

stopLockTask()

Solution

  • This issue is a difficult issue to deal with, but the solution is very simple. For anyone else facing the same problem, all you have to do is change your launchMode to single task. Once I updated my Manifest, I was able to remain pinned while changing Activities seamlessly.

    android:launchMode="singleTask"