Re: [android-developers] Why can't my GUI return back to recording mode despite having service? Someone HELP..
Hi, I believe that recording video while in the background is not supported. Trying to force this to happen is likely to result in random, undesirable behavior. Note that you have to go to work to even get to that point because when the user leaves your app your window's surface as well as the surface associated with a SurfaceView will be destroyed by the framework. There is not supported way to keep these around. On Sat, Apr 9, 2011 at 6:47 AM, lyrical.mas...@hotmail.com < lyrical.mas...@hotmail.com> wrote: > I'm creating an android application which act like a car blackbox, but > i run into problem as soon i start doing it, maybe partly because i'm > new to android/java but i've given 6more weeks to develop this > app... :'( > > But get back to my problem i had my service run the video recording > processes in the background so i should be able to leave the app for a > while and come back to the Video recording GUI with the surfaceview > but my application was force to close when i return to the app. So is > the problem related to onResume() method or something else? If its yes > what i should do in order to get my application GUI to return to the > video recording surfaceview and still running the background recording > using the service rather than giving me an error? > > Can someone please help me, i've really exhausted all ideas and to > make it worse i'm new to java/android thus making me very headache, i > really need some experience programmer to help me solve the > problem... > > public class CameraTest extends Activity implements > SurfaceHolder.Callback { > >private static final String TAG = "Exception"; > >public static SurfaceView surfaceView; >public static SurfaceHolder surfaceHolder; >public static Camera MainCamera; >public static boolean previewRunning; > >@Override >public void onCreate(Bundle savedInstanceState) { >super.onCreate(savedInstanceState); >setContentView(R.layout.main); > >surfaceView = (SurfaceView)findViewById(R.id.surface_camera); >surfaceHolder = surfaceView.getHolder(); >surfaceHolder.addCallback(this); > > > surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); > >Button btnStart = (Button) findViewById(R.id.button4); >btnStart.setOnClickListener(new View.OnClickListener() >{ >public void onClick(View v) >{ >startService(new Intent(getApplicationContext(), > ServiceRecording.class)); >} >}); > >Button btnStop = (Button) findViewById(R.id.button5); >btnStop.setOnClickListener(new View.OnClickListener() >{ >public void onClick(View v) >{ >stopService(new Intent(getApplicationContext(), > ServiceRecording.class)); >} >}); >} > >@Override >public void surfaceCreated(SurfaceHolder holder) { >MainCamera = Camera.open(); >if (MainCamera != null) { >Camera.Parameters params = MainCamera.getParameters(); >MainCamera.setParameters(params); >} >else { >Toast.makeText(getApplicationContext(), "Camera not > available!", > Toast.LENGTH_LONG).show(); >finish(); >} >} > >@Override >public void surfaceChanged(SurfaceHolder holder, int format, int > width, int height) { >if (previewRunning) { >MainCamera.stopPreview(); >} > >Camera.Parameters p = MainCamera.getParameters(); >p.setPreviewSize(320, 240); >p.setPreviewFormat(PixelFormat.JPEG); >MainCamera.setParameters(p); > >try { >MainCamera.setPreviewDisplay(holder); >MainCamera.startPreview(); >previewRunning = true; >} >catch (IOException e) { >Log.e(TAG,e.getMessage()); >e.printStackTrace(); >} >} > >@Override >public void onResume(){ >super.onResume(); > >} > >@Override >public void surfaceDestroyed(SurfaceHolder holder){ >MainCamera.stopPreview(); >previewRunning = false; >MainCamera.release(); >} > } > > My RecordingService.java Service file > public class ServiceRecording extends Service { > >@Override >public IBinder onBind(Intent intent) { >// TODO Auto-generated method stub >return null; >} > >private SurfaceView surfaceView; >private SurfaceHolder surfaceHolder; >public static Camera ServiceCamera; >private boolean RecordingStatus; >private MediaRecorder mediaRecorder; >private final int maxDurationInMs = 2; > >private static final String TAG = "Exception"; > >@Override >public void onCreate() { >super.onCreate(); >
[android-developers] Why can't my GUI return back to recording mode despite having service? Someone HELP..
I can't really imagine how useful hours of video shot in the pants pocket or inside the belt clip could be. But if I had to do it I would add a periodic alarm to check if the service is still alive and to restart it if not. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Why can't my GUI return back to recording mode despite having service? Someone HELP..
You can't run your app forever, it will get killed when memory is low, you can't really avoid it (on a non rooted device): apps aren't meant to run and consume resources forever. And I don't think that dumping a large amount of code at people is going to help, unless you can pinpoint your problem a little bit and try to narrow what you think is going wrong. Try instead thinking of what ways you can change the structure of your application to make it work to the android platform a little bit better. I understand that you want to have the app recording forever in the background, but is this even practical? I'm not sure... I think at least the phone will run out of power much more quickly... It's too bad uneducated bosses push these types of projects on people without knowing what capabilities the platform has, though. Kris On Sat, Apr 9, 2011 at 9:47 AM, lyrical.mas...@hotmail.com < lyrical.mas...@hotmail.com> wrote: > I'm creating an android application which act like a car blackbox, but > i run into problem as soon i start doing it, maybe partly because i'm > new to android/java but i've given 6more weeks to develop this > app... :'( > > But get back to my problem i had my service run the video recording > processes in the background so i should be able to leave the app for a > while and come back to the Video recording GUI with the surfaceview > but my application was force to close when i return to the app. So is > the problem related to onResume() method or something else? If its yes > what i should do in order to get my application GUI to return to the > video recording surfaceview and still running the background recording > using the service rather than giving me an error? > > Can someone please help me, i've really exhausted all ideas and to > make it worse i'm new to java/android thus making me very headache, i > really need some experience programmer to help me solve the > problem... > > public class CameraTest extends Activity implements > SurfaceHolder.Callback { > >private static final String TAG = "Exception"; > >public static SurfaceView surfaceView; >public static SurfaceHolder surfaceHolder; >public static Camera MainCamera; >public static boolean previewRunning; > >@Override >public void onCreate(Bundle savedInstanceState) { >super.onCreate(savedInstanceState); >setContentView(R.layout.main); > >surfaceView = (SurfaceView)findViewById(R.id.surface_camera); >surfaceHolder = surfaceView.getHolder(); >surfaceHolder.addCallback(this); > > > surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); > >Button btnStart = (Button) findViewById(R.id.button4); >btnStart.setOnClickListener(new View.OnClickListener() >{ >public void onClick(View v) >{ >startService(new Intent(getApplicationContext(), > ServiceRecording.class)); >} >}); > >Button btnStop = (Button) findViewById(R.id.button5); >btnStop.setOnClickListener(new View.OnClickListener() >{ >public void onClick(View v) >{ >stopService(new Intent(getApplicationContext(), > ServiceRecording.class)); >} >}); >} > >@Override >public void surfaceCreated(SurfaceHolder holder) { >MainCamera = Camera.open(); >if (MainCamera != null) { >Camera.Parameters params = MainCamera.getParameters(); >MainCamera.setParameters(params); >} >else { >Toast.makeText(getApplicationContext(), "Camera not > available!", > Toast.LENGTH_LONG).show(); >finish(); >} >} > >@Override >public void surfaceChanged(SurfaceHolder holder, int format, int > width, int height) { >if (previewRunning) { >MainCamera.stopPreview(); >} > >Camera.Parameters p = MainCamera.getParameters(); >p.setPreviewSize(320, 240); >p.setPreviewFormat(PixelFormat.JPEG); >MainCamera.setParameters(p); > >try { >MainCamera.setPreviewDisplay(holder); >MainCamera.startPreview(); >previewRunning = true; >} >catch (IOException e) { >Log.e(TAG,e.getMessage()); >e.printStackTrace(); >} >} > >@Override >public void onResume(){ >super.onResume(); > >} > >@Override >public void surfaceDestroyed(SurfaceHolder holder){ >MainCamera.stopPreview(); >previewRunning = false; >MainCamera.release(); >} > } > > My RecordingService.java Service file > public class ServiceRecording extends Service { > >@Override >public IBinder onBind(Intent intent) { >// TODO Auto-generated method stub >return
[android-developers] Why can't my GUI return back to recording mode despite having service? Someone HELP..
I'm creating an android application which act like a car blackbox, but i run into problem as soon i start doing it, maybe partly because i'm new to android/java but i've given 6more weeks to develop this app... :'( But get back to my problem i had my service run the video recording processes in the background so i should be able to leave the app for a while and come back to the Video recording GUI with the surfaceview but my application was force to close when i return to the app. So is the problem related to onResume() method or something else? If its yes what i should do in order to get my application GUI to return to the video recording surfaceview and still running the background recording using the service rather than giving me an error? Can someone please help me, i've really exhausted all ideas and to make it worse i'm new to java/android thus making me very headache, i really need some experience programmer to help me solve the problem... public class CameraTest extends Activity implements SurfaceHolder.Callback { private static final String TAG = "Exception"; public static SurfaceView surfaceView; public static SurfaceHolder surfaceHolder; public static Camera MainCamera; public static boolean previewRunning; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); surfaceView = (SurfaceView)findViewById(R.id.surface_camera); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); Button btnStart = (Button) findViewById(R.id.button4); btnStart.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startService(new Intent(getApplicationContext(), ServiceRecording.class)); } }); Button btnStop = (Button) findViewById(R.id.button5); btnStop.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { stopService(new Intent(getApplicationContext(), ServiceRecording.class)); } }); } @Override public void surfaceCreated(SurfaceHolder holder) { MainCamera = Camera.open(); if (MainCamera != null) { Camera.Parameters params = MainCamera.getParameters(); MainCamera.setParameters(params); } else { Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show(); finish(); } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (previewRunning) { MainCamera.stopPreview(); } Camera.Parameters p = MainCamera.getParameters(); p.setPreviewSize(320, 240); p.setPreviewFormat(PixelFormat.JPEG); MainCamera.setParameters(p); try { MainCamera.setPreviewDisplay(holder); MainCamera.startPreview(); previewRunning = true; } catch (IOException e) { Log.e(TAG,e.getMessage()); e.printStackTrace(); } } @Override public void onResume(){ super.onResume(); } @Override public void surfaceDestroyed(SurfaceHolder holder){ MainCamera.stopPreview(); previewRunning = false; MainCamera.release(); } } My RecordingService.java Service file public class ServiceRecording extends Service { @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } private SurfaceView surfaceView; private SurfaceHolder surfaceHolder; public static Camera ServiceCamera; private boolean RecordingStatus; private MediaRecorder mediaRecorder; private final int maxDurationInMs = 2; private static final String TAG = "Exception"; @Override public void onCreate() { super.onCreate(); RecordingStatus = false; ServiceCamera = CameraTest.MainCamera; surfaceView = CameraTest.surfaceView; surfaceHolder = CameraTest.surfaceHolder; } @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); if (RecordingStatus == false) startRecording(); return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); stopRecording(); RecordingStatus = false; } public boolean startRecording(){ try { Toast.makeText(getBaseContext(), "Reco