title: Using PixelCopy to take a screenshot
body: <p>I'm working on an Android Code Labs challenge (the first one) , that requires you to take a screen shot of an activity and emailing it to someone. </p>
  
  <p>There's only one activity and it displays "Hello World". </p>
  
  <p>So I decided to use API class PixelCopy - specifically the method:</p>
  
  <pre><code>PixelCopy.request(Window source, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
  </code></pre>
  
  <p>I understand that <code>PixelCopy.OnPixelCopyFinishedListener</code> provides this callback method: <code>onPixelCopyFinished(int copyResult)</code> where int copyResult is PixelCopy.SUCCESS etc if the copy operation was successful. </p>
  
  <p>I'm getting stuck because I don't understand how I should pass <code>PixelCopy.OnPixelCopyFinishedListener</code> into <code>PixelCopy.request()</code>. I mean what does the variable listener refer to ? what is its type ? what should listener be ?) </p>
  
  <p>I know that there is an easier way and that it to use API class Screenshot, Screenshot.capture() but I am a glutton for punishment. </p>
  
  <p>The code (as far as I've got with it) is below:</p>
  
  <pre><code>package com.experiments.azeem;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.graphics.Bitmap;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Handler;
  import android.text.Layout;
  import android.view.PixelCopy;
  import android.view.View;
  import android.view.Window;
  
  public class MainActivity extends AppCompatActivity {
      Bitmap bitmap;
      int width;
      int height;
      Window win;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          View view = (View) findViewById(R.id.activityScreen);
          width = view.getWidth();
          height = view.getHeight();
          win = this.getWindow();
          bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  
          PixelCopy.OnPixelCopyFinishedListener listener;
  
          PixelCopy.request (win, bitmap, listener.onPixelCopyFinished() , new Handler())
      }
  
  
  }
  </code></pre>