title: Which one is the better between using static var and passing object parameter?
body: <p>I want to write an APP to record screen, there are two way, RecordHelper_Method_A and RecordHelper_Method_B .</p>
  
  <p>In RecordHelper_Method_A, I define mMediaRecorder, MediaProjection mMediaProjection and mVirtualDisplay as static var, it's easy to invoke, such as <code>StartRecord( mContext, requestCode, resultCode,data)</code>, <code>StopRecord()</code>.</p>
  
  <p>and in RecordHelper_Method_B, I need to define mMediaRecorder, MediaProjection mMediaProjection in main Activity class, and pass the parameters when I invoke <code>StartRecord(mMediaRecorder, mMediaProjection,mVirtualDisplay)</code>, 'StopRecord(mMediaRecorder,mMediaProjection,mVirtualDisplay)`..., it's a little complex.</p>
  
  <p>I don't know which one is the better, and more I don't know if these static var can be released correctly in RecordHelper_Method_A when I end the APP.</p>
  
  <p>BTW, if you have the better way, would you please tell me ? Thanks!</p>
  
  <p><strong>RecordHelper_Method_A</strong></p>
  
  <pre><code>public class RecordHelper_Method_A {
  
      private static MediaRecorder mMediaRecorder;
      private static MediaProjection mMediaProjection;
      private static VirtualDisplay mVirtualDisplay;
  
      public static void StartRecord(Context mContext,int requestCode, int resultCode, Intent data){
  
          mMediaRecorder = new MediaRecorder();
          initRecorder();
  
          MediaProjectionManager mProjectionManager = (MediaProjectionManager) mContext.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
          mMediaProjection = mProjectionManager.getMediaProjection(resultCode, data);
  
          mVirtualDisplay=mMediaProjection.createVirtualDisplay("MainActivity",
                  400,600, 300,
                  DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                  mMediaRecorder.getSurface(), null, null);
  
          MediaProjectionCallback mMediaProjectionCallback = new MediaProjectionCallback();
          mMediaProjection.registerCallback(mMediaProjectionCallback, null);
  
          mMediaRecorder.start();
      }
  
      public static void StopRecord(){
          mMediaProjection=null;
          mMediaRecorder.stop();
          mMediaRecorder.reset();
          mMediaRecorder.release();
          mVirtualDisplay.release();
      }
  
  
      private static void initRecorder() {
          mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
          //...
      }
  
      private static class MediaProjectionCallback extends MediaProjection.Callback {
          @Override
          public void onStop() {
              mMediaRecorder.stop();
          }
      }
  }
  </code></pre>
  
  <p><strong>RecordHelper_Method_B</strong></p>
  
  <pre><code>public class RecordHelper_Method_B {
  
      public static void StartRecord(MediaRecorder mMediaRecorder,MediaProjection mMediaProjection,VirtualDisplay mVirtualDisplay){
  
          initRecorder(mMediaRecorder);
  
          mVirtualDisplay=mMediaProjection.createVirtualDisplay("MainActivity",
                  400,600, 300,
                  DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                  mMediaRecorder.getSurface(), null, null);
  
          MediaProjectionCallback mMediaProjectionCallback = new MediaProjectionCallback(mMediaRecorder);
          mMediaProjection.registerCallback(mMediaProjectionCallback, null);
  
          mMediaRecorder.start();
      }
  
      public static void StopRecord(MediaRecorder mMediaRecorder,MediaProjection mMediaProjection,VirtualDisplay mVirtualDisplay){
          mMediaProjection=null;
          mMediaRecorder.stop();
          mMediaRecorder.reset();
          mMediaRecorder.release();
          mVirtualDisplay.release();
      }
  
  
      private static void initRecorder(MediaRecorder mMediaRecorder) {
          mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
          //...
      }
  
      private static class MediaProjectionCallback extends MediaProjection.Callback {
          MediaRecorder mMediaRecorder;
          public MediaProjectionCallback(MediaRecorder mMediaRecorder){
              this.mMediaRecorder=mMediaRecorder;
          }
  
          @Override
          public void onStop() {
              mMediaRecorder.stop();
          }
      }
  
  }
  </code></pre>