Search code examples
androidandroid-orientation

Android Screen Orientation slow?


In my Android application i have loaded some images and data from the internet into expandable list view.And i have handled orientation changes as follows.

@Override
public Object onRetainNonConfigurationInstance() {
    isOrentationChnged=true; 
    final Object data = arrGroupelements;
    return data;

}

in my onCreate()

     if(!isOrentationChnged){
    new LongRunning().execute();

}else{

      if((String[][])getLastNonConfigurationInstance()==null){
        new LongRunning().execute();
      }else{
    arrGroupelements= (String[][]) getLastNonConfigurationInstance();
    expList.setAdapter(new ExpAdapter(cont));
      }
}

isOrentationChnged=false;

LongRunning is a AsynacTask which have used to get the data from the internet and it loads previously loaded data after orientation change (without getting new data from the internet again) but it is very slow.Is there any alternative way to do this efficiently ??


Solution

  • Finally i got simple way to speed up the orientation changes in an activity.

    IDEA:

    Each and every orientation change will recreate the activity the solution to this you can avoid the activity recreation by adding following code line to activity tag on your application's manifest file.

    android:configChanges="orientation|keyboardHidden|screenSize"
    

    above line avoid the activity recreation after orientation changes so your activity will be more responsive on orientation changes.