Sachin Kadian
Sachin Kadian

Reputation: 201

why onCreate reload again on orientation change

currently i am designing an application in which i have a list and alphabetic scrollbar for the list. To load the data in list, i am calling a method in onCreate and also calling one method to build the alphabetic scrollbar for the list. now my problem is that when i am changing the orientation , the onCreate method is calling again due to which both inside methods are also calling again. but i dont want to call the method that is loading the data into list again . means the method which is loading data should not be called again when changing orientation while the method which is building the scrollbar should be called again.

plz tell me how i can do that.

thanks in advance

Upvotes: 0

Views: 3544

Answers (3)

Payal
Payal

Reputation: 913

It happens because android assumes that a new activity has been created.

Use android :configChanges="orientation" in the activity part inside the android manifest

and dont forget to override this method :

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);    
}

This method will then be called on orientation change.Do the stuff you want to do in this code.

Upvotes: 2

Archie.bpgc
Archie.bpgc

Reputation: 24012

You can add this:

android:configChanges="orientation"

in the Manifest for required Activity tag

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    //reload your ScrollBars by checking the newConfig
}

Upvotes: 4

Manish Kumar
Manish Kumar

Reputation: 1062

you can add android:configChanges="orientation" in your manifest of activity and manually set the contentView or change the layout by overriding OnConfigurationChanged

Upvotes: 0

Related Questions