這是我的代碼。我想打電話給同兩個時間內for
環如何暫停活動,直到服務停止?
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
Intent camIntent = new Intent(getApplicationContext(),CameraService.class); //calling service first time
camIntent.putExtra("camNum", camIdx);
startService(camIntent);
} catch (RuntimeException e) {
e.printStackTrace();
}
} else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
try {
Intent camIntent = new Intent(
getApplicationContext(),CameraService.class); //calling service first time
camIntent.putExtra("camNum", camIdx);
startService(camIntent);
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
我想暫停時服務運行我的活動,否則我的活動將再次調用cameraService
而服務已在運行。我怎樣才能做到這一點?
聖牛!你有沒有聽說過縮進? –
我不認爲你正確地接近問題。看看[這個問題](http://stackoverflow.com/questions/9527728/prevent-multiple-copies-of-an-android-service) –