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 don't want that actually, what I want is the 3 random images stay still either on portrait or landscape mode.

halfer
  • 19,824
  • 17
  • 99
  • 186
hectichavana
  • 1,436
  • 13
  • 41
  • 71

2 Answers2

3

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

android:configChanges="keyboardHidden|orientation"
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
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,938
  • 3
  • 30
  • 48