第一个AIDL Service

问题1:客户端bind服务端失败:

Unable to start service Intent { act=com.example.aidltest.TestService flg=0x10000000 cmp=com.example.aidltest/TestService } U=0: not found

启动服务的Intent设置如下:

        Intent intent = new Intent();
        intent.setClassName("com.example.aidltest", "TestService");
        intent.setAction("com.example.aidltest.TestService");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

TestService配置如下:

       <service 
            android:name="com.example.aidltest.TestService"
            android:process=":remote"
            android:exported="true">
            <intent-filter >
                <action android:name="com.example.aidltest.TestService"/>
            intent-filter>
        service>

在与TestService同一个包中这样可以启动,但是在另外一个应用中无法启动,是因为设置Intent的class name时需要包含包名:

intent.setClassName("com.example.aidltest", "com.example.aidltest.TestService");

问题2:invork AIDL的接口时报错:

12-03 19:06:54.635 E/JavaBinder(29210): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

12-03 19:06:54.635 E/JavaBinder(29210):     at android.os.Handler.(Handler.java:200)

12-03 19:06:54.635 E/JavaBinder(29210):     at android.os.Handler.(Handler.java:114)

12-03 19:06:54.635 E/JavaBinder(29210):     at android.widget.Toast$TN.(Toast.java:411)

12-03 19:06:54.635 E/JavaBinder(29210):     at android.widget.Toast.(Toast.java:113)

12-03 19:06:54.635 E/JavaBinder(29210):     at android.widget.Toast.makeText(Toast.java:317)

12-03 19:06:54.635 E/JavaBinder(29210):     at com.example.aidltest.TestService$1.getValue(TestService.java:35)

12-03 19:06:54.635 E/JavaBinder(29210):     at com.example.aidltest.IAIDLTestService$Stub.onTransact(IAIDLTestService.java:57)

12-03 19:06:54.635 E/JavaBinder(29210):     at android.os.Binder.execTransact(Binder.java:446)

是因为在getValue接口中使用Toast不规范

你可能感兴趣的:(Android,Android)