在 onCreate 之外释放后如何重新初始化相机对象

How to reinitialize a camera object after is has been released outside of onCreate

我正在使用相机闪光灯进行摩尔斯电码应用。我在创建 class 时创建了一个新的相机对象。用户有一个按钮,用于重置并在需要时释放相机(如果他们想过早停止光莫尔斯序列)。

问题是,当他们按下重置按钮时,因为 activity 没有创建或再次加载,相机永远不会重新初始化 - 这是一个问题,因为 class 的方法,它is calling is used by another class 并在完成其功能后释放相机。我不确定如何以允许我执行此操作的方式构建代码。

我想知道是否有人 advice/suggestions 如何实现这个目标?

 //Camera object being declared
 Light light;


 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity__morse);

    //Camera object being initialized
    light = new Light
 }

  //Reset   user pressed a button
  public void reset(View view)
     {
         light.release();
     }

  //Releasing the camera
  public void release() {

    if(camera != null)
    {
        camera.stopPreview();
        camera.release();
        camera = null;
    }
   }

不要在onCreate 中初始化相机。 onStart执行,onStop释放