Reputation: 922
I'm still working on my app, and I have a new issue. On my WarikeActivity I have a button, this button send me to a MapActivity and then I want to get back to my WarikeActivy with some values from the MapActivity, I tried this:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putByteArray("byte_warike", byteArray);
super.onSaveInstanceState(savedInstanceState);
}
And then of course
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
byteArray = savedInstanceState.getByteArray("byte_warike");
foto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
imgFoto.setImageBitmap(foto);
}
But the app crash because byte_array is always null. Any idea about how to solve it? I was reading others posts by I cant solve that problem yet.
Thanks in advance.
Upvotes: 2
Views: 368
Reputation: 1074
OnSaveInstanceState and onRestoreInstanceState should actually only be used when the activity is being recreated and wants to save some info about itself. You, on the other hand, want to send info to the previous activity.
Reto Meier (a Google employee working on Android) has given a perfect response how this could be done here: How to pass the values from one activity to previous activity
Upvotes: 3