On this blog am going to explain how to save activity state when the activity is destroyed, I have been working on the android SDK platform, and it is a little unclear how to save an application's state.
You're explicitly destroying your activity such as by pressing back. Actually, the scenario in which this savedInstanceState is used, is when Android destroys your activity for recreation. For example, If you change the language of your phone while the activity was running (and so different resources from your project need to be loaded). Another very common scenario is when you rotate your phone to the side so that the activity is recreated and displayed in landscape. You can use this technique to store instance values for your application (selections, unsaved text, etc.).
To overcome this issue you need to override onSaveInstanceState(Bundle savedInstanceState) and write the application state values you want to change to the Bundle parameter, This bundle will be passed to onCreate if the process is killed and restarted.
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putBoolean("KeyBoolean", true);
savedInstanceState.putDouble("KeyDouble", 1.9);
savedInstanceState.putInt("KeyInt", 1);
savedInstanceState.putString("KeyString", "Welcome back to Android");
}
The Bundle is essentially a way of storing the values as Name-Value Pair, and it will get passed in to onCreate() and also onRestoreInstanceState(Bundle savedInstanceState) where you would then extract the values like this,
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
boolean myBoolean = savedInstanceState.getBoolean("KeyBoolean");
double myDouble = savedInstanceState.getDouble("KeyDouble");
int myInt = savedInstanceState.getInt("KeyInt");
String myString = savedInstanceState.getString("KeyString");
}
Thank you..
ReplyDeleteThis is such a great resource that you are providing and you give it away for free. https://www.buyyoutubesubscribers.in/
ReplyDeleteinstagram takipçi satın al
ReplyDeleteucuz takipçi
takipçi satın al
https://takipcikenti.com
https://ucsatinal.org
instagram takipçi satın al
https://perdemodelleri.org
https://yazanadam.com
instagram takipçi satın al
balon perdeler
petek üstü perde
mutfak tül modelleri
kısa perde modelleri
fon perde modelleri
tül perde modelleri
https://atakanmedya.com
https://fatihmedya.com
https://smmpaketleri.com
https://takipcialdim.com
https://yazanadam.com
yasaklı sitelere giriş
aşk kitapları
yabancı şarkılar
sigorta sorgula
https://cozumlec.com
word indir ücretsiz
tiktok jeton hilesi
rastgele görüntülü sohbet
fitness moves
gym workouts
https://marsbahiscasino.org
http://4mcafee.com
http://paydayloansonlineare.com
perde modelleri
ReplyDeletesms onay
mobil odeme bozdurma
Nft nasil alinir
ankara evden eve nakliyat
trafik sigortası
dedektör
web sitesi kurma
aşk kitapları
ataşehir arçelik klima servisi
ReplyDeletetuzla lg klima servisi
tuzla alarko carrier klima servisi
tuzla daikin klima servisi
çekmeköy toshiba klima servisi
ataşehir toshiba klima servisi
maltepe lg klima servisi
kadıköy lg klima servisi
maltepe alarko carrier klima servisi
minecraft premium
ReplyDeleteen son çıkan perde modelleri
yurtdışı kargo
nft nasıl alınır
lisans satın al
özel ambulans
en son çıkan perde modelleri
uc satın al