ServiceConnection::onServiceConnected not called e

2019-02-18 04:36发布

I've been trying to bind a service that was started on boot from an activity. The code for starting on boot was mostly taken from the instant messenger.

This is the AndroidManifest.xml definition for the 3 main components:

    <!-- 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>

The receiver starts the service on boot without any problems. However when I try to bind the service from my activity, Context::bindService returns true, but ServiceConnection::onServiceConnected is never called. Also, when I start the service from the activity it works as expected (ServiceConnection::onServiceConnected is called).

1条回答
小情绪 Triste *
2楼-- · 2019-02-18 05:09

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

startService() does not involve a ServiceConnection object.

Get rid of both the android:process="android.process.lifestylepp" lines from your manifest. That may be the source of your difficulty, and more importantly it is very unlikely you really need two processes and all the overhead that requires.

查看更多
登录 后发表回答