How to save the state of an ImageButton
<p>I am trying save an ImageButton's path in savedInstanceState in order not lose image for rotating the phone. But only one time it's working after that the path value i equal null (path==null)    </p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentLayout(R.layout.contact_information_wga800);

    if (savedInstanceState != null) {
        String profilefirstname = savedInstanceState.getString("firstname");
        firstname.setText(profilefirstname);
        String profilepath=savedInstanceState.getString("path");
        if(profilepath !=null){
            imagebutton.setImageBitmap( BitmapFactory.decodeFile(profilepath));
        }
    }

@Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
    savedInstanceState.putString("firstname", firstname.getText().toString());
    savedInstanceState.putString("path", media_path);
    super.onSaveInstanceState(savedInstanceState);
}
</code></pre>

<p>This is the part when I set in imagebutton bitmap using camera or android gallery.</p>

<pre><code>switch(requestCode) {
    case REQUEST_CAMERA:
        if (resultCode == RESULT_OK) {
            final Bundle extras = data.getExtras();
            bmp = (Bitmap)extras.get("data");
            if( bmp != null ) {
                final File f = this.getFileStreamPath("ping_media.jpg");
                if (f.exists()) { 
                    f.delete();
                }
                try {
                    final FileOutputStream out = this.openFileOutput("ping_media.jpg",MODE_PRIVATE);
                    bmp.compress(CompressFormat.JPEG, 12, out);
                    out.close();
                    media_path = f.getAbsolutePath();
                    if(dm.densityDpi&gt;=200) {
                        contactimg.setImageBitmap(getRoundedCornerBitmap(getResizedBitmap(bmp, 72, 72), 72));
                    } else if(dm.densityDpi&gt;130 &amp;&amp; dm.densityDpi&lt;200) {
                        contactimg.setImageBitmap(getRoundedCornerBitmap(getResizedBitmap(bmp, 48, 48), 48));
                    } else {
                        contactimg.setImageBitmap(getRoundedCornerBitmap(getResizedBitmap(bmp, 32, 32), 32));
                    }                               
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        break ;
    case REQUEST_SELECT_PHOTO:
        if( resultCode != 0 ) {
            final Cursor c = managedQuery(data.getData(),null,null,null,null);
            if (c.moveToFirst()) {
                media_path = c.getString(1);
                bmp = BitmapFactory.decodeFile(media_path);
                contactimg.setImageBitmap(getRoundedCornerBitmap( getResizedBitmap(bmp, 48, 48), 48));
            }
        }
        break;
}
</code></pre>

<p>should I do here so anytime rotating the phone I didn't lose imagebutton's bitmap.</p>
