• Chính Sách Bảo Mật
  • Liên Hệ
Batdongsandaithanh - Bản tin chuyên ngân hàng, tài chính, pháp luật Việt Nam
  • Home
  • Ngân Hàng
  • Pháp Luật
  • Tài Chính
  • Công Nghệ
  • Xem Thêm
    • Game
    • Âm Nhạc
    • Mẹo Vặt
    • Tổng Hợp
Friday, January 29, 2021
No Result
View All Result
  • Home
  • Ngân Hàng
  • Pháp Luật
  • Tài Chính
  • Công Nghệ
  • Xem Thêm
    • Game
    • Âm Nhạc
    • Mẹo Vặt
    • Tổng Hợp
No Result
View All Result
Batdongsandaithanh - Bản tin chuyên ngân hàng, tài chính, pháp luật Việt Nam
No Result
View All Result
Home Công Nghệ

How to Restore Variables When Rotating the Device – Android Studio Tutorial

admin by admin
July 13, 2020
in Công Nghệ
25
How to Restore Variables When Rotating the Device – Android Studio Tutorial
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter



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
Previous Post

DANH SÁCH GAME NHẸ MÀ HAY CHO MÁY CẤU HÌNH YẾU [PHẦN 1]

Next Post

Giá vàng hôm nay 9/7/2020 | Vàng 9999 chính thức vượt mốc 50 triệu | FBNC

Next Post
Giá vàng hôm nay 9/7/2020 | Vàng 9999 chính thức vượt mốc 50 triệu | FBNC

Giá vàng hôm nay 9/7/2020 | Vàng 9999 chính thức vượt mốc 50 triệu | FBNC

Comments 25

  1. Marinakulichok says:
    7 months ago

    If you have problem with rotating device make sure that you have auto mode in Emulator Settings->Display->Auto mode true/

    Reply
  2. RMA says:
    7 months ago

    Thank you for the video. It works well for screen rotation. 🧡

    Reply
  3. Ahmed Amsbred says:
    7 months ago

    I understand now why we have always (savedInstanceState: Bundle?) as parameter of onCreate methode !! thank you Sir

    Reply
  4. saheer ahmed says:
    7 months ago

    thank you sooooooo much. You are great.
    it worked finally.

    Reply
  5. J Birmingham says:
    7 months ago

    Great video!

    Reply
  6. Walid Pivano says:
    7 months ago

    Hi sir How can I use it for saving the position of recycle view when i click item and back yo recycler view

    Reply
  7. Frankelly Guzman says:
    7 months ago

    the G O A T

    Reply
  8. Zehaan Khan says:
    7 months ago

    welll done sir thankew

    Reply
  9. er er says:
    7 months ago

    The Best , as simple as that

    Reply
  10. Saidur Rahman Siam says:
    7 months ago

    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??

    Reply
  11. Roshan B says:
    7 months ago

    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

    Reply
  12. suraj chavhan says:
    7 months ago

    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

    Reply
  13. Kasperhoffmann Gaming - MORE CONTENT says:
    7 months ago

    When i do the setText in the if statement, the app crashes :/

    Reply
  14. ok ok says:
    7 months ago

    which was ändert 😀 trotzdem guter content!

    Reply
  15. Ari Sadraddin says:
    7 months ago

    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

    Reply
  16. NIKHIL SONAWANE says:
    7 months ago

    Thansk Coder!

    Reply
  17. Mustafa Abouelwafa says:
    7 months ago

    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

    Reply
  18. Jesus Dacoast says:
    7 months ago

    Best teacher ever 😎

    Reply
  19. Mike Ellertson says:
    7 months ago

    The code example you posted helped a lot. Thanks buddy!

    Reply
  20. tilcboy44 says:
    7 months ago

    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

    Reply
  21. phisitja เล่นดนตรีสนุกๆ พิสิฏฐ์ ศรีวิลาศ ฟลุ๊ก fluke says:
    7 months ago

    thank

    Reply
  22. Ismail Ghedamsi says:
    7 months ago

    It's works for activity but it doesn't works for a dialog fragment.Any solution?

    Reply
  23. kunal jaiswal says:
    7 months ago

    Seedhi batt no bakwas ♥️

    Reply
  24. Erlend Tyrmi says:
    7 months ago

    One like for not bloating the video with unnecessary stuff!

    Reply
  25. Muhammad Faisal says:
    7 months ago

    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..

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Xem Thêm

Singleton Design Pattern: Phân tích, trường hợp áp dụng

Singleton Design Pattern: Phân tích, trường hợp áp dụng

July 6, 2020
Xăm hình hoa văn ở bắp tay đẹp.

Xăm hình hoa văn ở bắp tay đẹp.

July 7, 2020
Hình Xăm Hoa Văn Đẹp Nhất Cho Nam | Pattern Tattoos For Men

Hình Xăm Hoa Văn Đẹp Nhất Cho Nam | Pattern Tattoos For Men

July 15, 2020
Có nên học LUẬT KINH TẾ không? |  #Vlog3

Có nên học LUẬT KINH TẾ không? | #Vlog3

July 6, 2020
Luật đấu thầu Việt Nam, pháp luật về đấu thầu, đấu thầu qua mạng, muasamcong, luật đấu thầu mới

Luật đấu thầu Việt Nam, pháp luật về đấu thầu, đấu thầu qua mạng, muasamcong, luật đấu thầu mới

July 11, 2020
Driver canon 2900 | Cách cài driver máy in Canon LBP 2900

Driver canon 2900 | Cách cài driver máy in Canon LBP 2900

July 21, 2020
Batdongsandaithanh – Bản tin chuyên ngân hàng, tài chính, pháp luật Việt Nam

Cập nhật tin tức về bất động sản cả nước

Được Xem Nhiều

  • Âm Nhạc
  • Bất Động Sản
  • Công Nghệ
  • Game
  • Mẹo Vặt
  • Ngân Hàng
  • Pháp Luật
  • Tài Chính
  • Tổng Hợp
  • Uncategorized

Tin Mới

Bất động sản liệu có xảy ra “bong bóng”?

Bất động sản liệu có xảy ra “bong bóng”?

January 27, 2021
Điêu đứng vì… bất động sản

Điêu đứng vì… bất động sản

January 27, 2021

© 2021 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Ngân Hàng
  • Pháp Luật
  • Tài Chính
  • Công Nghệ
  • Xem Thêm
    • Game
    • Âm Nhạc
    • Mẹo Vặt
    • Tổng Hợp

© 2021 JNews - Premium WordPress news & magazine theme by Jegtheme.