title: Android intent starts activity - how to use Bundle to pass parameters to a fragment
body: <p>I have activity MainActivity with a button. </p>
  
  <p>When the button is pressed, I start a new activity called ShowPictureActivity (which has one fragment called ShowPictureFragment).</p>
  
  <p>code to launch the ShowPictureActivity </p>
  
  <pre><code>intent = new Intent(LeakActivity.this, ShowPictureActivity.class);
  // parameters that I would like to pass to the ShowPictureFragment
  intent.putExtra("nRecNum", 1); // sample number
  intent.putExtra("pictureFileSpec", "picture/pictures/leak/leak.png"); // sample string
  startActivity(intent);
  </code></pre>
  
  <p>I know how to use the intent.putExtra to pass parameters to the activity ShowPictureActivity and I do know of a method to get the parameters from the fragment using the following code:      </p>
  
  <pre><code>ShowPictureFragment class
  @Override
  public View onCreateView
  {
      .
      .
      .
      // get parameters passed in the intent object
      intent = getActivity().getIntent();
      nRecNo = intent.getIntExtra("nRecNo", -1);
      pictureFileSpec = intent.getStringExtra("pictureFileSpec");
      .
      . 
  </code></pre>
  
  <p>From my reading, this is the not the best way to do this. I read that I should be using a bundle.</p>
  
  <p>I saw a snippet of code to build a bundle, but I don't know how to get it to the ShowPictureFragement.</p>
  
  <pre><code>// my sample bundle to pass to the ShowPictureFragment
  Bundle bundle = new Bundle();
  bundle.putInt("nRecNo", 3);
  bundle.putCharSequence("pictureFileSpec", "my\pictures\picture.png");
  </code></pre>
  
  <p>Can someone explain or give me an example showing how to create the bundle and pass it onto the a fragment.</p>
  
  <p>Thank you in advance!</p>