Mam niestandardowy widok, który rozszerza LinearLayout. Zaimplementowałem metody onSaveInstanceState() i onRestoreInstanceState(), aby zapisać bieżący stan widoku. Jednak żadne działanie nie jest podejmowane. Kiedy umieszczam dziennik wewnątrz tych dwóch metod, również nic nie pojawia się w Log Cat. Zakładam, że te dwie metody nie są nawet wywoływane. Czy ktoś może wyjaśnić, gdzie jest problem? Dzięki.onSaveInstanceState() i onRestoreInstanceState (stan paczek) nie są wywoływane?
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("currentPage", currentPage);
return bundle;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
currentPage = bundle.getInt("currentPage");
Log.d("State", currentPage + "");
super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
return;
}
super.onRestoreInstanceState(state);
}
miałem dokładnie ten sam problem, ale to dlatego, że mój zwyczaj 'View' nie miał' id' zestawu. Z dokumentów _ "Zauważ, że nawet jeśli włączone jest zamrażanie, widok nadal musi mieć przypisany identyfikator (przez setId (int)), aby jego stan został zapisany." _ –