title: Switch between Fragments and Show hide the AlertDialog and maintain state
body: <p>I have following scenario for my Android application.</p>
  
  <ul>
  <li>Step1: <code>Main Activity</code> loads the <code>Fragment1</code>.</li>
  <li>Step2: <code>Fragment1</code> shows a <code>AlertDialog</code> on some event as below
  <a href="http://i.stack.imgur.com/hDxSP.png" rel="nofollow">Fragment1 with AlertDialog</a></li>
  <li>Step3: Dialog has a camra icon on top right corner. When it is clicked it open camera to capture the photo as below</li>
  </ul>
  
  <pre>
  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  
  intent.putExtra(MediaStore.EXTRA_OUTPUT, getCapturedImagePath());
  
  ((Activity)context).startActivityForResult(intent, Constant.CAMERA_CAPTURE);
  
  ((Activity) context).overridePendingTransition(R.anim.right_to_left_layout, R.anim.left_to_right_layout);
  </pre>
  
  <ul>
  <li>Step4: When pictured is captured, we redirect to another fragment called <code>Fragment2</code> in which we show the captured photo using below code.  </li>
  </ul>
  
  <pre>
  FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
  
  //Hide Fragment1
  fragTrans.hide(fragment1);
  
  //Add Fragment2
  fragTrans.add(R.id.frame_container, fragment2, fragment2.getClass().getSimpleName());
  
  fragTrans.addToBackStack(fragment2.getClass().getSimpleName());
  
  fragTrans.commit();
  </pre>
  
  <p>It looks like <a href="http://i.stack.imgur.com/zGSjw.png" rel="nofollow">Fragment2 with AlertDialog</a></p>
  
  <p>Here we have few problems.</p>
  
  <p><strong>Problem 1:</strong> It shows the same <code>AlertDialog</code> on <code>Fragment2</code> which was actually opened in <code>Fragment1</code> and <code>Fragment2</code> is loaded behind that dialog.
  How to hide this dialog?</p>
  
  <p><strong>Problem 2:</strong> On the <code>Fragment2</code> we have <code>Correct</code> button when it is clicked we need to close the <code>Fragment2</code> and display the <code>Fragment1</code> with same alert dialog or you can say in same state it was before starting camera.
  How we can do that?</p>
  
  <p>Please guide.</p>
  
  <p>Thanks</p>