0

I build an app which shows 3 random images from an SQLite database. But when I rotate my device to landscape mode, the random images are changed. I dont want that acruallyy, what I want is the 3 random images stay still either on potrait or landscape mode.

Can anybody provide me a solution?

Thank you very much.

hectichavana
  • 1,396
  • 12
  • 40
  • 70

2 Answers2

3

Add below property in your manifest in that particular Activity node.

android:configChanges="keyboardHidden|orientation"
ingsaurabh
  • 15,170
  • 7
  • 51
  • 79
0

The reason for this happening is that the Activity is re-created when rotating to landscape mode. There are various ways around this:

  1. Move initialization out of Activity onCreate : Activity restart on rotation Android
  2. Move the logic to a separate class (which does the random picking) and get the data from this class (well, a Model class, to be more specific).
Community
  • 1
  • 1
sparkymat
  • 9,674
  • 3
  • 29
  • 48