Android
私が取り組んでいるアプリにはとの2 つのサービスがServiceA
ありServiceB
、前者が後者を開始します。GoogleAPIClientServiceB
を使用して、位置情報をインテントとして受け取り、他のクライアントに提供します。ServiceA
GoogleAPIClient を使用して、次ServiceB
のように場所を取得しようとしています:
@Override
public void onCreate() {
mGoogleApiClient = new GoogleApiClient.Builder(ServiceB.this)
.addConnectionCallbacks(mConnectionCallbacks)
.addOnConnectionFailedListener(mOnConnectionFailedListener)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
ServiceA
後で開始する方法については、次の 2 つのシナリオがありますServiceB
。
アクティビティによってバインドされ、開始されます。
Intent serviceA = new Intent(context, ServiceA.class); bindService(serviceA, mConnection, Context.BIND_AUTO_CREATE);
起動時に、
BroadcastReceiver
android.intent.action.BOOT_COMPLETED をリッスンする を介して。@Override public void onReceive(Context context, Intent intent) { Intent serviceA = new Intent(context, ServiceA.class); startWakefulService(context, serviceA); }
開始後、次のようにServiceA
開始します。ServiceB
Intent startIntent = new Intent(ServiceA.this, ServiceB.class);
startService(startIntent);
どちらの場合も、ServiceA と ServiceB が開始されます。
ケース 1 ( から開始) ではすべてが正常に機能しますActivity
が、ケース 2 (起動時に開始) を使用すると、ServiceB が開始されて が呼び出された後、数分間待ってもおよびにmGoogleApiClient.connect()
通知がありません。mOnConnectionFailedListener
mConnectionCallbacks
最終的に機能しない2つのケースの違いはわかりませんが、GoogleAPIClient
start に使用される Context と関係があると思われます。ServiceA
これは、Activity
ケース1でContext
提供され、BroadcastReceiver
ケース2で提供されるためです。
この問題を解決するには助けが必要です。
前もって感謝します。
更新 1
Google Play Services バージョン 8.4.0 を使用しています
compile 'com.google.android.gms:play-services:8.4.0'
更新 2
バージョン 9.2.1 に変更した後も、コールバックはありません。