When there are runtime configuration changes in your Android phone, like changing the screen orientation or the device’s language, your whole app process will be destroyed and recreated from scratch and together with it, all member variables will be reset. The system already takes care of default views like the text in an EditText field or the scrolling position of a RecyclerView or ListView. But we have to restore the variables of our activity ourselves and we do this by overriding onSaveInstanceState and passing the values to the outState Bundle. After the Activity has been recreated, there are 2 places where we can get our values back: onCreate or onRestoreInstanceState, which both get passed the savedInstanceState Bundle.
Source Code:
____________________
❗ Subscribe to the channel:
⏯ Watch more tutorials:
㊙ Help translating the videos:
💚 Support the content:
💬 Join the Discord chat:
🎧 Audiobooks and podcasts for programmers:
👶 How to get started with Android development:
📣 Follow Coding in Flow on social media:
Facebook:
Instagram:
Twitter:
Blog:
Nguồn: https://batdongsandaithanh.com/
Xem thêm bài viết khác: https://batdongsandaithanh.com/cong-nghe/
Xem thêm Bài Viết:
- [Photoshop cs6 căn bản] Bài 2 – Hướng dẫn dowload, cài đặt photoshop cs6 và crack photoshop
- [Viettel Sinvoice] Hướng dẫn Quản lý và Phát hành Hóa đơn điện tử
- Hướng dẫn cài Photoshop CS6 lên Kali Linux
- 10 Trang Web Cung Cấp Mẫu PowerPoint Đẹp Và Miễn Phí
- how to Create any country number WhatsApp Account
If you have problem with rotating device make sure that you have auto mode in Emulator Settings->Display->Auto mode true/
Thank you for the video. It works well for screen rotation. 🧡
I understand now why we have always (savedInstanceState: Bundle?) as parameter of onCreate methode !! thank you Sir
thank you sooooooo much. You are great.
it worked finally.
Great video!
Hi sir How can I use it for saving the position of recycle view when i click item and back yo recycler view
the G O A T
welll done sir thankew
The Best , as simple as that
dude tbh your videos helping me alot lately…thanks from my heart…btw one question my activity portrait layout has a dialog box in it..but when orientation change that dialog box needs to be reopen…is there any way??
Best explanation for save instance state. I have watched other videos on this topic but didn't understand clearly. But after watching this, I have a good idea of it
sir, I made my custom design in portrait mode but I want to use as it is in landscape mode without change how I can use it
When i do the setText in the if statement, the app crashes :/
which was ändert 😀 trotzdem guter content!
Thanks man that was so easy to understand but one question how can i save the state of something which is not a simple value like int or character like what if i want to save a WebView state
Thansk Coder!
Perfect – i did it and it worked – so nice
do you have the another Video for the same issue but when restarting the app -(not when changing the orientation) …?
thanks alot
Best teacher ever 😎
The code example you posted helped a lot. Thanks buddy!
Simple enough. But what if the data you want to preserve is a bitmap? As in image retrieved from camera… I'm trying to use bitmap=savedInstanceState.getParcelable("bitmap");
but app still crashing from orientation change and reverts back into camera mode
thank
It's works for activity but it doesn't works for a dialog fragment.Any solution?
Seedhi batt no bakwas ♥️
One like for not bloating the video with unnecessary stuff!
Great tutorial sir, but I have a question if this method can handle fetched data from Retrofit calls?
If yes, how to do it?
If no, then what other best practice should I use?
Right now i'm trying to learn LiveData but somehow it's quite hard for me to understand, now im looking for other alternative to make data survive due to screen rotation..