When you start another Activity, your previous Activity will be paused. The onPause() method will be triggered. so what you should do:
@Override
protected void onPause() {
super.onPause();
if (camera != null) {
camera.stopPreview();
camera.release();
camera = null;
}
}