私のコードでは、IntentService
位置の更新 (GPS またはネットワークの更新) をリッスンするために を使用しています。これIntentService
は、イベントを受信したときにトリガーされるためstartService()
、任意のアクティビティから開始されます。
public class AddLocationService extends IntentService implements LocationListener {
/*My code here*/
}
@Override
protected void onHandleIntent(Intent intent) {
if(getOldLoc() == null)
{
//Get a new location
this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TIME_INTERVAL_GPS, 0, this);
this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, TIME_INTERVAL_GPS, 0, this);
Log.d(AddLocationService.TAG, "Network listener started");
this.time_start_listening = System.currentTimeMillis();
mTimerThread mTimerRunnable = new mTimerThread();
this.timerThread = new Thread(mTimerRunnable);
this.timerThread.start();
}
else
/*REUSE OLD LOCATION*/
}
今私の問題は次のとおりです。2つのイベントがこれIntentService
を開始し、最初のイベントがまだ更新を要求している間に2番目のイベントが開始した場合、2番目のイベントは最初のイベントが完全に終了するまで待機するようにします(場所が見つかるか、タイマースレッドが終了します)。ただし、IntentService
が 2 回目に実行される (最初のインスタンスがまだ実行されている) ときはいつでも、ログが出力され、並行して実行されていたように実行されます。
ただし、主な目標はIntentService
それがシーケンシャルなものであるため、最初の意図が完了するまで2番目の意図を待たなければならないと思いました...
私は何かを誤解しましたか?