To Activity’s
To save the data
static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Salve todos seus dados aqui, lembrando que se for objeto é preciso ser serializable ou de preferencia parcelable
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Sempre chamar a super classe depois de salvar as instancias
super.onSaveInstanceState(savedInstanceState);
}
To recover the data
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //Sempre chamar a super classe primeiro
// Verifique se existe algo para restaurar
if (savedInstanceState != null) {
// Restaurando os valores padrão
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
} else {
// Não existe valores para restaurar
}
...
}
More details on this link
I recommend not using Asynctask and yes Retrofit for HTTP and for threads recommend using Rxandroid and Rxlifecycle to control the life cycle
https://developer.android.com/topic/libraries/architecture/guide.html
– itscorey
Related: What is savedInstanceState?
– ramaral
Thank you very much, @ramaral...exactly what I wanted. Problem solved.
– martins_