Stan aktywności -...
Click here to load reader
Transcript of Stan aktywności -...
Za
ga
dn
ien
ia u
zu
pe
łnia
jąc
e p
rog
ram
ow
an
ie w
sy
ste
mie
An
dro
id K
IK 2
01
8
Strona 1
Stan aktywności
Zapisywanie stanu aktywności
Odtwarzanie stanu aktywności
int wynik; // przykładowa zmienna (opisuje stan aktywności)
static final String WYNIK = "wynik"; // klucz
public void onSaveInstanceState(Bundle savedInstanceState)
{
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt(WYNIK, wynik);
}
public void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
wynik = savedInstanceState.getInt(WYNIK);
}
Za
ga
dn
ien
ia u
zu
pe
łnia
jąc
e p
rog
ram
ow
an
ie w
sy
ste
mie
An
dro
id K
IK 2
01
8
Strona 2
Stan aktywności
Klasa Bundle (pochodna od BaseBundle)
Zapis Odczyt
putBoolean(String key, boolean value) boolean getBoolean(String key)
putByte(String key, byte value)
putByteArray(String key, byte[] value)
byte getByte(String key)
byte getByte(String key, byte defaultValue)
byte[] getByteArray(String key)
putInt(String key, int value) int getInt(String key)
putFloat(String key, float value) float getFloat(String key)
putDouble(String key, double value) double getDouble(String key)
putChar(String key, char value) char getChar(String key)
putCharSequence (String key, CharSequence value) CharSequence getCharSequence(String key)
putString(String key, String value) String getString(String key)
putSerializable(String key, Serializable value) Serializable getSerializable(String key)
Analogicznie do typu danych byte (drugi wiersz w powyższej tabeli), dostępne są
metody dla pojedynczych wartości poszczególnych typów oraz tablic takiego typu.