Android问题 - 拍照时使用处理程序

时间:2015-01-28 12:26:17

标签: android timer camera handler runnable

我试图在我的Android应用程序中向用户显示总图像占用时间(计时器)。

我做了什么:

片段开始时我正在启动Handler。 (即)我已经在我的" onCreateView"中启动了处理程序。方法如下。

MainFragment:

private long startTime = 0L;
private long timeInMillies = 0L;
private long timeSwap = 0L;
private long finalTime = 0L;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.capture,
                container, false);
    TextView textview = (TextView)rootView.findViewById(R.id.timer);

    startTime = SystemClock.uptimeMillis();
    Handler myHandler = new Handler();
    Runnable updateTimer = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;
            int seconds = (int) (finalTime / 1000);
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            milliseconds = milliseconds % 60 ;
            textview.setText(String.format("%02d", seconds) + ":" + String.format("%02d", milliseconds) + "s");
            myHandler.postDelayed(this, 0);
        }

    };
    myHandler.postDelayed(updateTimer, 0);

    .
    .
    .
    return rootView;
}

我想要的是什么:

处理程序运行良好,计时器运行时不会延迟( 00.00,00.01,00.02,00.03,00.04,......,10.32 ),直到我开始调用&#34 ; camera.takePicture(null,null,pictureCallback); "。我打电话给" camera.takePicture "计时器以秒延迟显示时间( 00.00,00.01,00.02,00.03,延迟,02.30,02.31,02.32,延迟,04.03,04.04,......

@Override
public void onResume() {
    super.onResume();
    .
    .
    .
    camera.takePicture(null, null, pictureCallback);
}

会出现什么问题?有没有人面对这个问题?我该如何解决这个问题?

0 个答案:

没有答案