代码之家  ›  专栏  ›  技术社区  ›  kloffy

即使context::bindservice返回true,也没有调用serviceConnection::onServiceConnected?

  •  4
  • kloffy  · 技术社区  · 15 年前

    我一直在尝试绑定从活动启动时启动的服务。启动时启动的代码主要取自 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。此外,当从活动启动服务时,它按预期工作(Service EnnCn::OnService EnnEntruts被调用)。

    1 回复  |  直到 13 年前
        1
  •  2
  •   CommonsWare    15 年前

    另外,当我从 它按预期工作的活动 (服务连接::OnServiceConnected 被调用)。

    startService() 不涉及 ServiceConnection 对象。

    把这两个都去掉 android:process="android.process.lifestylepp" 你的舱单上的行。这可能是您困难的根源,更重要的是,您不太可能真正需要两个流程和所有需要的开销。