Handle Activity State Changes using onSaveInstanceState | Android Tutorial 2020

Опубликовано: 10 Октябрь 2024
на канале: Daily Coding
14,695
272

📱 Handle Activity State Changes | Activity state changes using onSaveInstanceState and onRestoreInstanceState. Preserving and restoring an activity’s UI state in a timely fashion across system-initiated activity or application destruction is a crucial part of the user experience. In these cases the user expects the UI state to remain the same, but the system destroys the activity and any state stored in it.

📌 Read Article:
🔗 https://dailycoding.in/android/handle...

So, when you rotate your device and the screen changes orientation, Android usually destroys your application’s existing Activities and Fragments and recreates them.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (savedInstanceState != null) {
counter = savedInstanceState.getInt("key_counter", 0);
} else {
counter = 0;
}
txtTotal.setText("" + counter);
}

=======================================
📌 BLOG
🌐 www.dailycoding.in

📌 Related Topics:
◀️ Introduction of Android Application Components
   • Introduction of Android Application C...  

◀️ What is Activity?
   • Android Activity - What is Activiy | ...  

◀️ Activity LifeCycle
   • Android Activity - What is Activiy | ...  

◀️ Android Intent | Explicit & Implecit Intent
   • Android Implicit Intent and Explicit ...  

◀️ Android Custom Seekbar - Complete Guide
   • Android Custom Seekbar | How to Custo...  

◀️ Shared Preferences (Data Persistance) Complete Playlist:
🔗 https://bit.ly/3bFfl2J

📌 Available Resources Links:
🔗 Git Project Link: https://github.com/subhojitdp/SavedIn...

📜 References:
🔗 Google Docs Link: https://developer.android.com/topic/l...

=======================================
💡 Why do you need to Subscribe to my channel?
1. It's FREE (you just need the google mail account)
2. Up to date (every my videos in your mail)
3. Help me to grow up this channel
4. More subscribers = More events.
5. Subscribe channel #DailyCoding
========================================

🔷🔷 JOIN NOW 🔷🔷
***************************************************
👉 Telegram Channel: https://t.me/DailyCodingYT
👉 Telegram Group: https://t.me/DailyCodingOfficial

👉 Facebook Page:   / dailycoding.in  
***************************************************

You might be asking yourself these below questions:
How to save Activity State on rotation?
How to screen orientation change without losing data?
How to save activity state when orientation changes in android?
How to save activity state in android?
How to use onSaveInstanceState and onRestoreInstanceState?

🙏 Thank you 🙏
#dailycoding #AndroidAppDevelopment #SavedInstanceState