Android Lollipop becoming device admininistrator doesn't work

旧时模样 提交于 2019-12-05 09:09:54

Seems it was the singleInstance launchMode option that caused the problem, I'm still interested to know why it causes the problem on Lollipop and not on other versions.

For now, setting launchMode to singleTask solves the issue, and seems to still fit with the design of the app's flow.

The root cause of this error message is in DeviceAdminAdd.java. There is this check:

if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
         Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
         finish();
         return;
}

This check was already there in 4.0.1 : API level 14 !

The Intent subject of this check is the Intent triggering the action : DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.

From the docs :

A "singleInstance" activity permits no other activities to be part of its task.

It don't explain the difference between API 21 and API<21 , but it explain why the FLAG_ACTIVITY_NEW_TASK is set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!