Finishing Activity after recording video (using CWAC-Camera library)

250 views Asked by At

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.

0

There are 0 answers