0

I am working with voice recognition and surface view in my app and my app crashes when I press home button and when I again launch the application from background it crashes...

Here is my concern ... 1) if I open camera in onCreate() method and closed camera on onPause() method and when I launch app from the back it crashed

2) if I put camera opening code onResume() only then camera doesn't start after onActivityResult() because it has conflicting code.

3) if I put camera opening on code in both the onCreate() and onResume() app crashes because camera object is already occupied and then again asking for camera resource in onResume() lead to null pointer error.

how can I resolve this issue. any help will greatly appreciated.

logcat:

06-20 14:54:17.452: E/AndroidRuntime(24570): FATAL EXCEPTION: main
06-20 14:54:17.452: E/AndroidRuntime(24570): java.lang.NullPointerException
06-20 14:54:17.452: E/AndroidRuntime(24570):    at com.client.mirrorapp.CameraPreview.surfaceCreated(CameraPreview.java:43)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.SurfaceView.updateWindow(SurfaceView.java:554)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.SurfaceView.access$000(SurfaceView.java:81)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:693)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1762)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2642)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.os.Looper.loop(Looper.java:154)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at android.app.ActivityThread.main(ActivityThread.java:4624)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
06-20 14:54:17.452: E/AndroidRuntime(24570):    at dalvik.system.NativeStart.main(Native Method)
DjP
  • 4,537
  • 2
  • 25
  • 34
  • "crashes app" indicates that you should take a look at the Stacktrace and post it in your question. – Ben Weiss Jun 20 '14 at 09:23
  • @keyboardsurfer updated logcat error for 2 (second) condition.. – DjP Jun 20 '14 at 09:27
  • Put your oncreate code to onresume metod i think you have created surfaceview in oncreate that`s why it gives error in onresume method. make surface view in onresume method. – Rhn Bhadani Jun 20 '14 at 09:34
  • @user1632209 please refer second codition in which I there is conflict code in onActivityResult and in onResume so apart from that any other thing ... – DjP Jun 20 '14 at 09:51
  • There are various examples of camera + SurfaceView in Grafika (https://github.com/google/grafika). In particular, the TextureFromCameraActivity class has a comment at the top about managing the Camera and Surface objects in different stages of the app lifecycle. (It can be tricky to get it just right.) – fadden Jun 20 '14 at 19:43

0 Answers0