title: How can I stop video recording when user presses the back button on an Android custom camera
body: <h2><em>NOTE:</em> This resembles a duplicate but none of the others solved my problem</h2>
  
  <p>@Hitesh Tarbundiya's <a href="https://stackoverflow.com/a/55175530/4268050">answer</a> in <strong>Step 2</strong> solved my problem</p>
  
  <p>I am using the <a href="https://github.com/natario1/CameraView" rel="nofollow noreferrer">natario1 CameraView library</a> for android to record video. </p>
  
  <p>I am working with a <code>Fragment</code>.</p>
  
  <p>I have written code to </p>
  
  <ol>
  <li><p>Stop the video recording</p></li>
  <li><p>Save the recorded video </p></li>
  <li><p>Update the media gallery with the newly created video file</p></li>
  </ol>
  
  <p>But what I can't figure out now is where to call those methods when the user presses the back button or home button on their phone <em>before</em> the fragment is destroyed.</p>
  
  <p>I have tried calling the methods from the <code>onPause()</code> <code>onStop()</code> <code>onDestroyView()</code> and <code>onDestroy()</code> but have not succeeded.</p>
  
  <p>Would appreciate some advice, thanks.</p>