cosu icon indicating copy to clipboard operation
cosu copied to clipboard

LockTaskMode is not set after reboot in complete example

Open AngularPadawan opened this issue 8 years ago • 3 comments

I followed step 3 in the tutorial and things worked fine so far. When I rebooted the device from the locked activity, it also correctly boots again into the locked activity.

However, when I check what locked activities are there using adb shell dumpsys activity activities, it is not listed there (it was before the reboot).

When I add a TextInput to LockedActivity and bring up the soft keyboard, it correctly shows only the back button. After the reboot, it shows the home and recents buttons again.

To me, this looks like the Activity fails to enter lockTaskMode after the reboot.

Android 6.0, Kernel version 3.18.19, LenovoPad TB3-X70F

Thanks, Martin

AngularPadawan avatar Jun 10 '17 13:06 AngularPadawan

I am experiencing the same issue. Rebooting on a screen in lockTaskMode fails to set it back to lockTaskMode. Found this in the logs:

07-05 15:45:14.583   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_ENTERING flg=0x10 cmp=com.example.package/.DeviceAdminReceiver (has extras) } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}
07-05 15:45:14.584   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_EXITING flg=0x10 cmp=com.example.package/.DeviceAdminReceiver } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}

It looks like it tries to enter lock task mode and immediately exits.

PaulNorton avatar Jul 05 '17 19:07 PaulNorton

Sorry for late answering, but... Anyone has this problem can do this tricky work in first (LAUNCHER/HOME) activity (e.g. MainActivity):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mSharedPreferences.getBoolean(KEY_PREF_RECREATED, false)) {
        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, false).apply();

        // start LOCK TASK here
    } else {
        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, true).apply();

        finish(); // close the app
        startActivity(new Intent(this, MainActivity.class)); // reopen the app
        return;
    }

    setContentView(R.layout.activity_main);

    // other codes
}

pourqavam avatar Jun 02 '18 20:06 pourqavam

Happening on a Android 6.0 Alcatel Y with kiosk mode and launcher set.

Anyone have a solution?

yurik94 avatar Dec 02 '20 01:12 yurik94