編輯:關於Android編程
Android L[Android5.X.X] 版本通過Intent隱式啟動service時將會報出以下錯誤:
AndroidRuntime( 792): java.lang.IllegalArgumentException: Service Intent must be explicit
詳細信息:
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.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
sdksourcesandroid-21androidappContextImpl.java
class ContextImpl extends Context {
......
private void validateServiceIntent(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 are not safe: + service
+ + Debug.getCallers(2, 3));
}
}
}
......
}
上面源碼中藍色加粗部分:service.getComponent() == null && service.getPackage() == null
表明通過intent啟動service時, 需要指定Intent的ComponentName信息:intent.setComponent(xxx),或指定Intent的setPackage(包名),如果兩者都沒有指定的話將會報以上錯誤。尤其在framework層啟動APP層的service時,如果是隱式啟動service,可能會導致系統進程掛掉,出現不斷重啟的現象。
Intent intent = new Intent();
ComponentName componentName = new ComponentName(pkgName,serviceName);
intent.setComponent(componentName);
context.startService(intent);
Intent mIntent = new Intent();
mIntent.setAction(XXX.XXX.XXX);//Service能夠匹配的Action
mIntent.setPackage(pkgName);//應用的包名
context.startService(mIntent);
Binding to a Service
Fragment介紹Android在3.0中引入了Fragments的概念,主要目的是用在大屏幕設備上(如平板電腦上)支持更加動態和靈活的UI設計。平板電腦的屏幕要比手機
一、proc文件系統傳統意義上的文件系統是用於塊設備上信息的存儲,/proc這個目錄是一個虛擬文件系統,它放置的數據都是在內存當中,所以這個目錄本身不占用任何硬盤空間。主
這兩天在學習的過程中,發現一個講Unity的unet組件的好教程,在這裡分享給大家。新建一個 UnetProject。新建一個GameObject重命名為Network
觀察者模式有時被稱作發布/訂閱模式,觀察者模式定義了一種一對多的依賴關系,讓多個觀察者對象同時監聽某一個主題對象。這個主題對象在狀態發生變化時,會通知所有觀察者對象,使它