Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top