문제

Im developing an app that download tweets from twitter. When my app change orientation, the activity loads again the tweets (it downloads again the same tweets). So whats the best solution for a case like this ? Is using android:configChanges="orientation|keyboardHidden|screenSize" a way to go ? I have read that is a bad practice. Thanks

도움이 되었습니까?

해결책

You can override onSaveInstanceState and onRestoreInstanceState to avoid downloading same tweets again.

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putSerializable(<Key>, <Value>);
    super.onSaveInstanceState(savedInstanceState);
}

When the orientation is changed, restore the saved tweets.

[Edit]
Alternatively, you can do it without overriding onRestoreInstanceState:

public void onCreate(Bundle savedInstanceState) {
  if (savedInstanceState!= null) {
    value = savedInstanceState.getSerializable(<Key>);
  }
}

More information here.

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