如何在服务停止之前暂停活动?

时间:2014-03-26 12:23:10

标签: android service camera android-activity

这是我的代码。我想在CameraService循环

中两次调用相同的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。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

你需要添加一个监听器,我添加了一些示例代码。请遵循这一点,它必须是有帮助的。

service.SearchEmployee(searchStr, Offset, NO_OF_ITEM_IN_PAGE, onlyManager, new IRequestListener<List<Employee>>() {
                        @Override
                        public void onRequestFailed(String message) {

                                Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
                                requestCompleted = true;


                        }

                        @Override
                        public void onRequestCompleted(List<Employee> data) {

                                if (Offset == 1)
                                    cacheMap.put(searchStr, data);

                                tempList = data;
                                requestCompleted = true;
                                lock.notifyAll();
                            }

                    });