Android使用AIDL实现进程通信中Service报错的问题
最近在学习AIDL实现进程通信过程中,一个远程服务Service(应用中无Activity组件,只有一个Service和aidl文件),一个客户端Client(一个Activity和aidl文件)。然后不知道为什么每回打开客户端都会报告服务已停止,搞了半天最后才知道,都是文件命名的坑啊。以下是我Service工程文件。
一开始也不知道怎么想的应用包名起成这样,而在配置文件中,又写成这样:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mgy.remoteservice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name=".StudentQueryService"<!-- 注意这里 -->
android:enabled="true">
<intent-filter >
<action android:name="com.mgy.studentremotequery"/>
</intent-filter>
</service>
</application>
</manifest>
然后可想而知,这能跑起来才怪。。。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mgy.remoteservice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name="com.mgy.remote.service.StudentQueryService"<!-- 注意这里 -->
android:enabled="true">
<intent-filter >
<action android:name="com.mgy.studentremotequery"/>
</intent-filter>
</service>
</application>
</manifest>
再次修改,顺利的跑起来了。
当然,直接改包名也是可以的。
一定要注意命名!