In the background service, the Device Manager activation interface appears.
Some functions of the Company project must be implemented by using the Device Manager. Therefore, if the background polling determines whether the Device Manager is activated, the Device Manager activation page is displayed.
However, in the background service, the page for redirecting to the activation device manager has been flashed back. After checking for a long time, locate the cause:
E: \ android-6.0.0_r1 \ frameworks \ base \ core \ java \ android \ app \ ContextImpl. java
This is because the following judgment is added to start the Activity in the background service:
@ Override
Public void startActivity (Intent intent, Bundle options ){
WarnIfCallingFromSystemProcess ();
If (intent. getFlags () & Intent. FLAG_ACTIVITY_NEW_TASK) = 0 ){
Throw new AndroidRuntimeException (
"Calling startActivity () from outside of an Activity"
+ "Context requires the FLAG_ACTIVITY_NEW_TASK flag ."
+ "Is this really what you want ");
}
Mmainthread.getinstrumentation(cmd.exe cStartActivity (
GetOuterContext (), mMainThread. getApplicationThread (), null,
(Activity) null, intent,-1, options );
}
No exception is reported only when the task stack is added. However
Android source code in E: \ android-6.0.0_r1 \ packages \ apps \ Settings \ src \ com \ android \ settings \ DeviceAdminAdd. java
The following error message is displayed when you jump to the Device Manager:
If (getIntent (). getFlags () & Intent. FLAG_ACTIVITY_NEW_TASK )! = 0 ){
Log. w (TAG, "Cannot start ADD_DEVICE_ADMIN as a new task ");
Finish ();
Return;
}
Therefore, you can only start StartActivity in Activity to jump to the activation interface of the Device Manager.