In the background service, the Device Manager activation interface appears.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.