In the Android, most developers provide the camera or video recorder application in the Android Market, but they only record the video on the foreground view. In that case, we can’t keep to record video when other services are coming. For example, when you are recording the video, and then you want to change to other application to do some work. So you have to return to the home screen. This will stop the video recording process.
To solve the problem, we can apply the service for the video recording. When the video recorder is starting with a service, the video recorder can be run in the background. In that case, you can keep to record the video screen even though you are accessing other application.
This article shows an example for making video record as a service on Android.
1. First of all, you have to create a Android project for developing the video recorder application.
2. Initialize the camera and media record instances.
3. For starting the Service, you have to new an Intent instance to indicate which the service you want to start.
Indicate the source activity and the target service in intent variable.
The Intent.FLAG_ACTIVITY_NEW_TASK is set for intent to indicate the activity will become a new task.
When the service will be started, the first activity has to be closed. So we call the finish() to close the activity.
Intent intent = new Intent(CameraRecorder.this, RecorderService.class);
4. You can reference to the Android SDK website: MediaRecorder for recording the video.
You have to follow the steps of MediaRecorder.
You can reference this code.
mMediaRecorder = new MediaRecorder();
The sample project implements a service for video recording is uploaded to the Github. You can find out the repository and download it from this link: CameraRecorder in Github.