title: Refresh Activity using onResume()
body: <p>I have a Flashlight Activity. Normally it works fine but When I go to any other activity, it stop working!</p>
  
  <p>So I want to refresh the code when I back to the Flashlight Activity.</p>
  
  <p>I think refreshing using <code>onResume()</code> would help me best, But how to do it?</p>
  
  <pre><code>public class FlashLightActivity extends Activity {
  
  //flag to detect flash is on or off
  private boolean isLighOn = false;
  
  private Camera camera;
  
  private Button next1, next2;
  
  @Override
  protected void onStop() {
      super.onStop();
  
      if (camera != null) {
          camera.release();
      }
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
  
          next1 = (Button) findViewById(R.id.ebtn28_answer);
          next1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  Intent myIntent = new Intent(view.getContext(), FullScreen.class);
                  startActivityForResult(myIntent, 0);
              }
  
          });
  
      next2 = (Button) findViewById(R.id.buttonFlashlight);
  
      Context context = this;
      PackageManager pm = context.getPackageManager();
  
      // if device support camera?
      if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
          Log.e("err", "Device has no camera!");
          return;
      }
  
      camera = Camera.open();
      final Parameters p = camera.getParameters();
  
      next2.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
  
              if (isLighOn) {
  
                  Log.i("info", "torch is turn off!");
  
                  p.setFlashMode(Parameters.FLASH_MODE_OFF);
                  camera.setParameters(p);
                  camera.stopPreview();
                  isLighOn = false;
  
              } else {
  
                  Log.i("info", "torch is turn on!");
  
                  p.setFlashMode(Parameters.FLASH_MODE_TORCH);
  
                  camera.setParameters(p);
                  camera.startPreview();
                  isLighOn = true;
  
              }
  
          }
      });
  
  }
    }                                                              
  </code></pre>