hectichavana
hectichavana

Reputation: 1446

Android: random images changed when device is rotated to landscape mode

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.

Upvotes: 0

Views: 381

Answers (2)

ingsaurabh
ingsaurabh

Reputation: 15267

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

android:configChanges="keyboardHidden|orientation"

Upvotes: 3

sparkymat
sparkymat

Reputation: 10028

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).

Upvotes: 0

Related Questions