AIDL通信 android 在5.0以使用隱式Intent方式來啓動Service的問題

轉自: http://www.cnblogs.com/xiaoxiaing/p/6278996.html

在使用AIDL進行通信的時候需要開啓遠程服務,在這裏發現android5.0以後不能使用隱式intent :需要指定Intent的ComponentName組件名稱信息:

intent.setComponent(xxx),

或指定

Intent的setPackage("包名"),

如果兩者都沒有指定的話將會報錯。
尤其在framework層啓動APP層的service時,如果是隱式啓動service,可能會導致系統進程掛掉,出現不斷重啓的現象。

解決方法1:

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

解決方法2:

Intent mIntent = new Intent();
mIntent.setAction("XXX.XXX.XXX");//Service能夠匹配的Action
mIntent.setPackage(pkgName);//應用的包名
context.startService(mIntent);

AIDL通信Demo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章