android – 即使Context :: bindService返回true,也没有调用ServiceConnection :: onServiceConnected?

我一直在尝试绑定从活动启动时启动的服务.启动时启动的代码主要来自
instant messenger.

这是3个主要组件的AndroidManifest.xml定义:

    <!-- Receiver -->
    <receiver android:name=".receiver.LifestylePPAutoStarter"
        android:process="android.process.lifestylepp">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>

    <!-- Service -->
    <service android:name=".service.LifestylePPService"
        android:process="android.process.lifestylepp"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="edu.gatech.lifestylepp.ILifestylePPService" />
            <action android:name="edu.gatech.lifestylepp.SERVICE" />
        </intent-filter>
    </service>

    <!-- Activity -->
    <activity android:name=".app.LifestylePPActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

接收器在启动时启动服务没有任何问题.但是,当我尝试从我的活动绑定服务时,Context :: bindService返回true,但从不调用ServiceConnection :: onServiceConnected.此外,当我从活动启动服务时,它按预期工作(调用ServiceConnection :: onServiceConnected).

最佳答案

Also, when I start the service from
the activity it works as expected
(ServiceConnection::onServiceConnected
is called).

startService()不涉及ServiceConnection对象.

从清单中删除android:process =“android.process.lifestylepp”行.这可能是您遇到困难的根源,更重要的是,您不太可能真正需要两个进程和所需的所有开销.

点赞