Handle Activity State Changes using onSaveInstanceState | Android Tutorial 2020

Share this & earn $10
Daily Coding
Published at : 17 Nov 2020
470 views
10
1

📱 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/handle-activity-state-changes-in-android-applications/

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);
}

=======================================
➧ VISIT HERE
🌐 www.dailycoding.in

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

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

📜 References:
🔗 Google Docs Link: https://developer.android.com/topic/libraries/architecture/saving-states

=======================================
💡 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 Real Tech (Stay Connected).
=======================================
🔗 Facebook Page: https://www.facebook.com/dailycodingguide/

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
javaHandle Device Configuration Changesandroid studio

How to fix error "unable to resolve host"

How to fix error "unable to resolve host"

How long do antibodies protect you after you have had COVID-19?

How long do antibodies protect you after you have had COVID-19?

Stray Kids "바보라도 알아" M/V

Stray Kids "바보라도 알아" M/V

เมื่อหุ่นยนต์ กลายเป็นที่ระบายอารมณ์ทาง..ของมนุษย์ (สปอยหนัง) Life Like

เมื่อหุ่นยนต์ กลายเป็นที่ระบายอารมณ์ทาง..ของมนุษย์ (สปอยหนัง) Life Like

South Africa| Homes you can purchase in South Africa right now

South Africa| Homes you can purchase in South Africa right now

Annually Meaning

Annually Meaning

The Spirit of Counsel and Might // Brian Guerin // School of the 7 Spirits

The Spirit of Counsel and Might // Brian Guerin // School of the 7 Spirits

I Made a Coke Can USB Portable Power Bank - Phone Charger!

I Made a Coke Can USB Portable Power Bank - Phone Charger!

How to create a free account in NETFLIX

How to create a free account in NETFLIX

Céline Dion - Alone (Live in Boston, 2008)

Céline Dion - Alone (Live in Boston, 2008)

Love and Death - Chemicals Music Video

Love and Death - Chemicals Music Video

What is your preferred training format?

What is your preferred training format?

This is the ONE thing ALL GOOD GOLFERS DO NATURALLY (it's not a swing position)

This is the ONE thing ALL GOOD GOLFERS DO NATURALLY (it's not a swing position)

Preview for fabric covered hard cover journal cover tutorial.

Preview for fabric covered hard cover journal cover tutorial.

not steady - paloma mami (by manu rios)

not steady - paloma mami (by manu rios)

COVID RELATIONSHIP (How We Manage Long Distance)

COVID RELATIONSHIP (How We Manage Long Distance)

Fast Hand Sounds and Hand Movements ASMR

Fast Hand Sounds and Hand Movements ASMR

Paano Mag-Design ng Greenhouse for Succulents / Mga Dapat I-consider

Paano Mag-Design ng Greenhouse for Succulents / Mga Dapat I-consider

VAST -  "I dont have anything"

VAST - "I dont have anything"

An explanation of equipment and tools used when updating an ADMIRALTY Standard Nautical Chart

An explanation of equipment and tools used when updating an ADMIRALTY Standard Nautical Chart

League of Nations - Successes and Failures - GCSE History

League of Nations - Successes and Failures - GCSE History

Everybody Roasts Franklin

Everybody Roasts Franklin

My Family Gives Their Impression On Ghana Before And After Their Visit/ Sunday Dinner

My Family Gives Their Impression On Ghana Before And After Their Visit/ Sunday Dinner

Touring a $8,995,000 Los Angeles Modern Home with a Really COOL Guest House!

Touring a $8,995,000 Los Angeles Modern Home with a Really COOL Guest House!

Laura Story - You Cannot Be Stopped (Official Lyric Video)

Laura Story - You Cannot Be Stopped (Official Lyric Video)

Stem Cell Therapy (512) 450-0101 new non-surgical healing procedures

Stem Cell Therapy (512) 450-0101 new non-surgical healing procedures

Warmth - Parallel

Warmth - Parallel

The brain-changing benefits of exercise | Wendy Suzuki

The brain-changing benefits of exercise | Wendy Suzuki

Forty Four

Forty Four

Forza Horizon 4 - How To Raise Your Tuner Level

Forza Horizon 4 - How To Raise Your Tuner Level

Roxette - Fading Like A Flower

Roxette - Fading Like A Flower

What's inside Amazon Returns?

What's inside Amazon Returns?

IELTS Part 3 Questions  and Answers about Globalization

IELTS Part 3 Questions and Answers about Globalization

WHAT COULD GO WRONG! SPORTS COMPILATION

WHAT COULD GO WRONG! SPORTS COMPILATION

wait.. it’s better!?..

wait.. it’s better!?..

The Worst Mistakes Economics Explaned Made in 2020

The Worst Mistakes Economics Explaned Made in 2020

Top 10 Religion's Symbols and Their Meanings

Top 10 Religion's Symbols and Their Meanings

Tubeless Tape Installation

Tubeless Tape Installation

TUTORIAL: Beethoven's "Moonlight" (3rd movt.) at Five Progressively Increasing Tempos

TUTORIAL: Beethoven's "Moonlight" (3rd movt.) at Five Progressively Increasing Tempos

BOXING || CARDIO || NEW YEARS CELEB || 33 - 100

BOXING || CARDIO || NEW YEARS CELEB || 33 - 100

Over the Rainbow

Over the Rainbow

GASTEI 4.200 DIAMANTES NA CONTA DO MENINO HUMILDE NO FEE FIRE💎💎

GASTEI 4.200 DIAMANTES NA CONTA DO MENINO HUMILDE NO FEE FIRE💎💎

Tamela Mann - God provides - Joyful Noise BET

Tamela Mann - God provides - Joyful Noise BET

Journey - Open Arms (Live)

Journey - Open Arms (Live)

The Story's Beginning - A Hearth's Warming Tail

The Story's Beginning - A Hearth's Warming Tail

Top 5 stock metrics to analyze a company.

Top 5 stock metrics to analyze a company.

TIARA - Provide (feat. Bayou)

TIARA - Provide (feat. Bayou)

What is error and types of computer network

What is error and types of computer network

HermitCraft 7 | WHAT COULD POSSIBLY GO WRONG?! [E42]

HermitCraft 7 | WHAT COULD POSSIBLY GO WRONG?! [E42]