Reputation: 484
I have problem with my activity when I change the phone's orientation, the activity runs the onCreate method agaian (and my program downloads a file in onCreate)
how can I make activity not restart after orientation change ?
Upvotes: 0
Views: 133
Reputation: 49976
You should properly handle you configuration changes, you can use onSaveInstanceState
to store information that given file was already downloaded - ie. with path to it. In onCreate Bundle savedInstanceState
will be non null after configuration change, you can read information on your downloaded file from it.
If you will use android:configChanges
, then it will not solve your problem. Once you go to other app, android might destroy your activity, when you will go back to your app, android will recreate it again - and you again will start downloading your file.
Upvotes: 1
Reputation: 360
android:configChanges is good, if you're not changing anything, when orientation of activity will be changed.
You can also read about handling orientation change in documentation:this and this
Upvotes: 1
Reputation: 12919
This is the default behaviour for Android Activities - They get recreated whenever you change the device configuration.
To change this behaviour, add this line to the Activity declaration in your AndroidManifest.xml
:
android:configChanges="orientation|keyboardHidden|screenSize"
This will tell the system that you handle orientation changes for your Activity on your own.
Upvotes: 3