title: Android Intent, Action Create Document, Opens the file explorer multiple times creating duplicate 0b files
body: <p>I am developing an app for filling pdf forms, I am saving the pdf to the internal storage and then sharing it using the intent ACTION_CREATE_DOCUMENT. This intent returns a URI which i then copy my local pdf into. </p>
  
  <p>All this works fine however the intent opens a file explorer popup so that the user can choose where to save the pdf, and here in lies the problem, when the user presses SAVE; the app creates a 0b file in that location (as it should), but then it reopens the file explorer prompting the user to SAVE again, this happens two or three times and then it finally close for real at which point the pdf data overwrites the latest of the now numerous 0b files.</p>
  
  <pre class="lang-java prettyprint-override"><code>public int WRITE_REQUEST_CODE=45;
     ...
             @RequiresApi(api = Build.VERSION_CODES.KITKAT)
      public void buttonExport(View view) {
          Toast.makeText(this, "Exporting - This will take around 1min", Toast.LENGTH_LONG).show();
  
          // Template of PDF with acrofields (template.pdf).
          // TRY to open the pdf stored in the raw res directory
          // then convert it to a file object by copying it
          try {
              //
  
                  InputStream inputStream =null;
  
              if (template.equals("crfminortemplate")){
                   inputStream = getResources().openRawResource(R.raw.crfminorpdftemplat);
              }
              else   if (template.equals("crfmajortemplate")){
                   inputStream = getResources().openRawResource(R.raw.crfmajorpdftemplat);
              }
              File tempFile = new File(getFilesDir(),template);
              //
              copyFile(inputStream, new FileOutputStream(tempFile));
  
              // Now Questions res is tempFile ..
          } catch (IOException e) {
              throw new RuntimeException("Can't create temp file ", e);
          }
  
  
          try {
              PDFManipulation.fillPDF(view, template, fileName, Answers);
          } catch (IOException e) {
              e.printStackTrace();
          }
          catch (NullPointerException e)
          {
              e.printStackTrace();
          }
  
          Toast.makeText(this, "Export Complete - save to drive or email", Toast.LENGTH_LONG).show();
  
         sharePDF(getFilesDir()+"/"+fileName+".pdf");
  
  
      }
  
      private void sharePDF(String PDFPPath) {
          Uri path = FileProvider.getUriForFile(this, "com.example.cst_app_v3", new File(getFilesDir(),fileName+".pdf"));
          Intent shareIntent = new Intent();
  
          shareIntent.setAction(Intent.ACTION_SEND);
          shareIntent.putExtra(Intent.EXTRA_TEXT, "Sent from CST App Android " + PDFPPath);
          shareIntent.putExtra(Intent.EXTRA_STREAM, path);
          shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
          shareIntent.setType("application/pdf");
          startActivityForResult(shareIntent,0);
          Intent saveIntent = new Intent();
          saveIntent.setAction(Intent.ACTION_CREATE_DOCUMENT);
          saveIntent.putExtra(Intent.EXTRA_TITLE,fileName+".pdf");
          saveIntent.addCategory(Intent.CATEGORY_OPENABLE);
          saveIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
          saveIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
          saveIntent.setType("application/pdf");
          startActivityForResult(saveIntent,WRITE_REQUEST_CODE);
  
          Intent chooserIntent = Intent.createChooser(shareIntent, "Share or Save ...");
          Intent[]arrayofintent = {saveIntent};
          chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,arrayofintent);
          startActivityForResult(chooserIntent,0);
          startActivity(chooserIntent);
  
          Log.d("Alert",path.getAuthority()+" "+ path.getPath());
      }
  
  
   @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  
          if (resultCode == RESULT_OK &amp;&amp; requestCode == WRITE_REQUEST_CODE) {
         //DO THE COPY PASTE FROM LOCAL to THE URI data
         }
  }
  </code></pre>
  
  <p>Again </p>
  
  <p>I want the user to start the save intent and have the file selector popup once let the user name the file and choose the save location, press save and then return to my the my app where the pdf is copied to the location they specified</p>
  
  <p>if anyone knows/has experienced this issue or thinks they know what might be happening it would be great to hear from you.</p>