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);起動時に、
BroadcastReceiverandroid.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()通知がありません。mOnConnectionFailedListenermConnectionCallbacks
最終的に機能しない2つのケースの違いはわかりませんが、GoogleAPIClientstart に使用される 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 に変更した後も、コールバックはありません。