문제

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 ??

도움이 되었습니까?

해결책

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.

다른 팁

As per David unless isOrentationChnged is set to static it will always be false when your Activity is recreated.

You don't really need that variable anyway just do this in onCreate:

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

This way if the activity is being recreated then your data will be used, otherwise the longrunning operation will run.

By the way I don't see you using arrGroupelements in your Adapter constructor.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top