title: Android, Saving and loading a bitmap in cache from different activities
body: <p>I have i bitmap that needs to show in a new activity, so i cahe it and in the opened activity i try to load it but i get a nullPointerException. Here i save the image : </p>
  
  <pre><code>File cacheDir = getBaseContext().getCacheDir();
  File f = new File(cacheDir, "pic");
  
  try {
      FileOutputStream out = new FileOutputStream(
              f);
      pic.compress(
              Bitmap.CompressFormat.JPEG,
              100, out);
      out.flush();
      out.close();
  
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  Intent intent = new Intent(
          AndroidActivity.this,
          OpenPictureActivity.class);
  startActivity(intent);
  </code></pre>
  
  <p>and then in the new activity i try to open it :</p>
  
  <pre><code>public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
  
      File cacheDir = getBaseContext().getCacheDir();
      File f = new File(cacheDir, "pic");     
      FileInputStream fis = null;
      try {
          fis = new FileInputStream(f);
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      Bitmap bitmap = BitmapFactory.decodeStream(fis);
  
      ImageView viewBitmap = (ImageView) findViewById(R.id.icon2);
      viewBitmap.setImageBitmap(bitmap);
      setContentView(R.layout.open_pic_layout);
  </code></pre>