title: Pick image from gallery and load it into the imageview of the particular activity and into a navigation drawer imageview in another activity
body: <p>I have a Activity Profile in which the user can update his profile picture. At the same time I have a navigation drawer in which the updated profile picture should be loaded into the imageview of the navigation drawer.I need a code in which the user can choose image from gallery or camera and crop it to fit into the imageview and the same image should be loaded into the image view of a navigation drawer in the main activity.</p>
  
  <p>Here is the code of my ProfileAcitvity In this code we can choose the image from gallery and is loaded into the image view. But when we try to go back to the previous activity and again come back to profile activity the updated image is no there. wehave to upload it again.</p>
  
  <pre><code>public class Profile extends AppCompatActivity {
      ImageView picture;
      private int PICK_IMAGE_REQUEST = 1;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_profile);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          }
          picture = (ImageView)findViewById(R.id.picture);
          picture.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  //Toast.makeText(getApplicationContext(),"image clicked",Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent();
  // Show only images, no videos or anything else
                  intent.setType("image/*");
                  intent.setAction(Intent.ACTION_GET_CONTENT);
  // Always show the chooser (if there are multiple options available)
                  startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
              }
          });
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == PICK_IMAGE_REQUEST &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null &amp;&amp; data.getData() != null) {
  
              Uri uri = data.getData();
              myPrefsEdit.putString("url", uri.toString());
              myPrefsEdit.commit();
  
              try {
                  Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                  // Log.d(TAG, String.valueOf(bitmap));
  
                  picture.setImageBitmap(bitmap);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>This is the navigation drawer image
     <a href="http://i.stack.imgur.com/JTLd3.jpg" rel="nofollow">http://i.stack.imgur.com/JTLd3.jpg</a></p>
  
  <p>Thanks in advance</p>