Long story short, I have to develop a small application that displays a random image when the app launches. I discovered quickly that when the device orientation changed, the main activity re loaded and a new image was chosen. Someone on this site helped me solve this by declaring a null image outside of OnCreate()
, and then inside of OnCreate()
I have this:
image = (Bitmap) getLastNonConfigurationInstance();
if (image == null) {
image = getRandomImage();
}
setRandomImage(image);
This works nicely. My problem now is that I have to add a random "quote of the day" to the app and I can't make this work. A new quote is being pulled when the device orientation changes. I thought that maybe the following would work, but it doesn't:
message = (String) getLastNonConfigurationInstance();
if (message == null) {
message = getRandomMessage();
}
setRandomMessage(message);
I'm probably just not understanding how getLastNonConfigurationInstance()
works, so if someone could help me out I'd appreciate it.