Android [android5.x.x] service startup issues with Android L

Source: Internet
Author: User

a description of the problem


Android l[android5.x.x] Version The following error will be reported when the service is implicitly launched via intent:

Androidruntime (792): Java.lang.IllegalArgumentException:Service Intent must be explicit


"Declaration" Welcome reprint, but please keep the article original source:http://blog.csdn.net/yelangjueqi/article/details/46754581


More information:

01-02 07:52:44.736 D/powermanagerservice/smartstandby (792): sendDetectFaceIntent:com.wtk.smart.standby.DETECT_ Face_action
01-02 07:52:44.738 W/contextimpl (792): Calling a method in the system process without a qualified User:android.app.Cont extimpl.startservice:1813 com.android.server.power.powermanagerservice.senddetectfaceintent:4155 com.android.server.power.powermanagerservice.handledetectfacecase:4137 com.android.server.power.powermanagerservice.access$4400:100 com.android.server.power.powermanagerservice$ powermanagerhandler.handlemessage:3306
01-02 07:52:44.744 E/androidruntime (792): * * * FATAL EXCEPTION in SYSTEM process:powermanagerservice
01-02 07:52:44.744 e/Androidruntime (792): Java.lang.IllegalArgumentException:Service Intent must be explicit: Intent {act=com.wtk.smart.standby.detect_face_action (has extras)}
01-02 07:52:44.744 E/androidruntime (792): at Android.app.ContextImpl.validateServiceIntent (contextimpl.java:1801)
01-02 07:52:44.744 E/androidruntime (792): at Android.app.ContextImpl.startServiceCommon (contextimpl.java:1830)
01-02 07:52:44.744 E/androidruntime (792): at Android.app.ContextImpl.startService (contextimpl.java:1814)
01-02 07:52:44.744 E/androidruntime (792): At Com.android.server.power.PowerManagerService.sendDetectFaceIntent ( powermanagerservice.java:4155)
01-02 07:52:44.744 E/androidruntime (792): At Com.android.server.power.PowerManagerService.handleDetectFaceCase ( powermanagerservice.java:4137)
01-02 07:52:44.744 E/androidruntime (792): At com.android.server.power.powermanagerservice.access$4400 ( POWERMANAGERSERVICE.JAVA:100)
01-02 07:52:44.744 E/androidruntime (792): at com.android.server.power.powermanagerservice$ Powermanagerhandler.handlemessage (powermanagerservice.java:3306)
01-02 07:52:44.744 E/androidruntime (792): at Android.os.Handler.dispatchMessage (handler.java:111)
01-02 07:52:44.744 E/androidruntime (792): at Android.os.Looper.loop (looper.java:194)
01-02 07:52:44.744 E/androidruntime (792): at Android.os.HandlerThread.run (handlerthread.java:61)
01-02 07:52:44.744 E/androidruntime (792): at Com.android.server.ServiceThread.run (servicethread.java:46)
01-02 07:52:44.752 V/settingsprovider (792): Call (Global:dropbox:system_server_crash) for 0
01-02 07:52:44.753 D/settingsprovider (792): LookupValue table Global Cache.fullymatchesdisk () dropbox:system_server_ Crash
01-02 07:52:44.757 V/settingsprovider (792): Call (Global:logcat_for_system_server_crash) for 0
01-02 07:52:44.757 D/settingsprovider (792): LookupValue table Global Cache.fullymatchesdisk () logcat_for_system_ Server_crash


Two problem analysis


A. Locating problem points


Sdk\sources\android-21\android\app\contextimpl.java

Class Contextimpl extends Context {
......
private voidvalidateserviceintent(Intent service) {
if (service.getcomponent () = = null && service.getpackage () = = NULL) {
if (getapplicationinfo (). targetsdkversion >= Build.version_codes. LOLLIPOP) {
IllegalArgumentException ex = new IllegalArgumentException (
"Service Intent must be explicit: "+ service");
Throw ex;
} else {
LOG.W (TAG, "implicit intents with StartService is not safe:" + Service
+ "" + debug.getcallers (2, 3));
}
}
}
......
}


B. Analysis process


Above source in blue bold part:service.getcomponent () = = null && service.getpackage () = = NULL

When you start a service through intent, you need to specify the ComponentName information for intent: intent.setcomponent (XXX), or intent ("package name") that specifies Setpackage. If neither is specified, the above error will be reported. in particular, when the framework layer starts the service of the app layer, if the service is implicitly started, it can cause the system process to hang, and the phenomenon of a constant restart occurs.

three-way solution
refer to a

Intent Intent = new Intent ();
ComponentName componentname = new ComponentName (pkgname,servicename);
Intent.setcomponent (componentname);
Context.startservice (Intent);


Reference Two

Intent mintent = new Intent ();
Mintent.setaction ("XXX.XXX.XXX");//service can match the action
Mintent.setpackage (pkgname);//application's package name
Context.startservice (mintent);


Four extended website


Binding to a Service
The Context.bindservice () method now requires a explicit Intent, and throws an exception if given an implicit Intent. To ensure your app are secure, use a explicit intent when starting or binding your Service, and does not declare intent filt ERS for the service.
In other words, implicit intent is not allowed to start the service after 5.0


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android [android5.x.x] service startup issues with Android L

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.