title: Passing captured Image from Camera2 Api to another Activity
body: <p>I have just to use Camera2 API(using the code design of <a href="https://github.com/googlesamples/android-Camera2Basic" rel="nofollow noreferrer">https://github.com/googlesamples/android-Camera2Basic</a>) to build an application. Earlier, i used camera API  to do the same, and the results were quite good. Right now, I am able to capture the image and save it in File.
  I am stuck at this point : 
  <strong>I want to send the captured image to another activity in which i want to display the image in an imageview</strong>. Unlike Camera API, Camera2 Api is quite cumbersome dealing with this.
  This is a sample of the code where i am trying to pass the inten, i.e right after i get the output variable set, i would like to starActivity, to pass it on to the next Activity. :</p>
  
  <pre><code> /**
   * Saves a JPEG {@link Image} into the specified {@link File}.
   */
  private static  class ImageSaver implements Runnable   {
  
      /**
       * The JPEG image
       */
  
  
      private final Image mImage;
      /**
       * The file we save the image into.
       */
      private final File mFile;
  
      ImageSaver(Image image, File file) {
          mImage = image;
          mFile = file;
  
      }
  
      @Override
      public void run() {
          ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
          byte[] bytes = new byte[buffer.remaining()];
          buffer.get(bytes);
          FileOutputStream output = null;
          try {
              output = new FileOutputStream(mFile);
              output.write(bytes);
             Intent i = new Intent(current activity, next activity)
                     startActivity(i);
  
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              mImage.close();
  
              if (null != output) {
                  try {
                      output.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  
  }
  </code></pre>
  
  <p>This is where(in the camera2Basic code) i want to pass the activity call, to the next activity. This issue am facing here, is that there isnt any Context variable, or instance of the Main activity Available in this class, and as the enclosing method is static, i am not able to start the activity/pass the intent.</p>
  
  <p>i have updated it with the code which i am using, but i am looking for how i can transfer between activities when i use camera2 API. cause in camera api, it is easy. the problem is the run() function runs on a UI thread, which inturn is called when the ImageReader has been initialized. The whole code is just the Camera2Basic code. the only thing am  trying to add is to transfer between activities and send the image captured to the new activity.</p>
  
  <p>Would be great if i could get an idea how to proceed. 
  Thank you!</p>