[Android L] About Android L Service Startup, androidservice

Source: Internet
Author: User

[Android L] About Android L Service Startup, androidservice

I. Problem Description


When Android L [Android5.X. X] implicitly starts the service through Intent, the following error is reported:

AndroidRuntime (792): java. lang. IllegalArgumentException: Service Intent must be explicit


[Statement] Welcome to reprint, but please keep the original source of the article: http://blog.csdn.net/yelangjueqi/article/details/46754581


Details:

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. contextImpl. 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. login. loop (login. 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


Problem 2


A. Locate the problem


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

Class ContextImpl extends Context {
......
Private void validateServiceIntent (Intent service ){
If (Service. getComponent () = null & service. getPackage () = null){
If (getApplicationInfo().tar getSdkVersion> = Build. VERSION_CODES.LOLLIPOP ){
IllegalArgumentException ex = new IllegalArgumentException (
"Service Intent must be explicit:" + service );
Throw ex;
} Else {
Log. w (TAG, "Implicit intents with startService are not safe:" + service
+ "" + Debug. getCallers (2, 3 ));
}
}
}
......
}


B. analysis process


The blue bold Section in the source code above:Service. getComponent () = null & service. getPackage () = null

Indicates that when the service is started using intent, the ComponentName information of Intent must be specified: intent. setComponent (xxx) or setPackage ("package name") of the specified Intent. If neither of them is specified, the above error is reported.Especially when the framework layer starts the service at the APP layer, if the service is started implicitly, the system process may be suspended and the service will be restarted continuously.

 

Solution 3
Reference 1

Intent intent = new Intent ();
ComponentName componentName = new ComponentName (pkgName, serviceName );
Intent. setComponent (componentName );
Context. startService (intent );


Reference 2

Intent mIntent = new Intent ();
MIntent. setAction ("XXX. XXX. XXX"); // the Action that the Service can match
MIntent. setPackage (pkgName); // package name of the application
Context. startService (mIntent );


4. extended official website


Binding to a Service
The Context. bindService () method now requires an explicit Intent, and throws an exception if given an implicit intent. to ensure your app is secure, use an explicit intent when starting or binding your Service, and do not declare intent filters for the service.
That is to say, the implicit Intent method cannot be used to start the Service after 5.0.


Copyright statement: This article is the author (http://blog.csdn.net/yelangjueqi) original articles, not allowed by the author can not be reproduced.

Related Article

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.