0

I have put together a small camera app but have got a problem.

When I resume my app and call onResume() I have to reinitialize everything (that is, reopen the camera and create a surfaceview that serves as a camera preview).

Now, my onResume() looks like this:

@Override
public void onResume() {
    super.onResume();
    openCamera();
    startCameraPreview();
}

The problem is that the methods in onResume(), namely openCamera() and startCameraPreview(), take a lot of time to finish. And therefore my app takes a lot longer to open up which is not a very nice user experience.

The question is: How can I fix this problem? I already tried using AsyncTask but there I ran into the issue of trying to update the UI from a thread other than the main thread.

Any ideas?

user2426316
  • 7,131
  • 20
  • 52
  • 83
  • **Why** are those methods slow? Are you aware that it is perfectly possible for another thread to update the main thread? `Interface`, `Handler`, `Receiver` etc. – Simon Feb 06 '14 at 21:23
  • If you use AsyncTask. the onPostExecute method allows you to update the Main thread. see this : http://developer.android.com/reference/android/os/AsyncTask.html – Tobiel Feb 06 '14 at 21:23
  • Yes, it is preferable to open camera on a background thread. But still the camera callbacks could interfere with UI. To make sure these callbacks don't make your app unresponsive, you can follow a simple tutorial [here](http://stackoverflow.com/a/19154438/192373). – Alex Cohn Feb 07 '14 at 07:22
  • From the code you published, it is not clear where UI updates are involved in `onResume()`. – Alex Cohn Feb 07 '14 at 07:24

0 Answers0