0

I am working on an application that automatically invokes an activity to take a video every few seconds.

The activity is started from a service as follows.

Intent intent1 = new Intent(context,CwacCamActivity.class);
intent1.setAction(GlobalVariables.TAKE_VIDEO_ACTION);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);//have tried without including this too.
context.startActivity(intent1);

As per the recommendations on the best time to start recording the video,

I start recording the video in

public void autoFocusAvailable()

Here is the code

try {
    record();
} catch (Exception e) {
    e.printStackTrace();
}

//THread to stop the video after stipulated time ( 5 seconds for example)...
new Thread(new Runnable() {
    @Override
    public void run() {
        //RUnnable to let the record go on for the requested time...

            try {
                Thread.sleep(5000);
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            stopRecording();
                            getActivity().finish();    
                        } catch (IOException e) {
                            e.printStackTrace();
                            Log.v(GlobalVariables.TAG,"error is"+e.getMessage());
                        }    
                    }
                });
            } catch (Exception e) {
                Log.v(GlobalVariables.TAG,"error is"+e.getMessage()
            }
    }
}).start();

When i try the above code by making the activity as MAIN and Launcher, it closes perfectly fine but when running the activity from the Service, it keeps restarting the activity and the whole app crashes in the process.

When taking a picture, it makes sense to finish the activity in the SavePicture().I am not sure if this is the right place to finish the activity or even stopRecording for that matter.However stopRecoring works and the videos are saved as they are supposed to .

I have tried a ton of different things but to no avail.I feel like I am missing something very simple.

Any help is appreciated as I am out of ideas at this point.

SteveIrwin
  • 115
  • 2
  • 14
  • "I am working on an application that automatically invokes an activity to take a video every few seconds" -- that is *so* not a use case for this library. "it keeps restarting the activity" -- what is "it"? What does "restart" mean? – CommonsWare Nov 29 '14 at 22:26
  • It might be not a use case but don't you think it will replicate a user waiting for the preview, then recording a video and exiting the app? Also Ideally the video should only record once and the activity should finish after that but in this case, the recording starts again which causes some weird state and the whole application crashes because of that.Any help is appreciated. – SteveIrwin Nov 30 '14 at 06:19
  • "don't you think it will replicate a user waiting for the preview, then recording a video and exiting the app?" -- as you note, you are launching from a service, which is not going to be normal camera app behavior. "but in this case, the recording starts again" -- then you are going to need to set up breakpoints or logging to determine why. For example, is your service starting the activity again? – CommonsWare Nov 30 '14 at 11:48

0 Answers0