rememberSaveable عبر التدوير
حافظ على الحالة أثناء تغييرات الإعدادات
rememberSaveable عبر التدوير درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Rotation Problem
Rotate the screen and your tap counter snaps back to zero. That is because a configuration change recreates the whole Activity.
remember Isn't Enough
remember survives recomposition, but not Activity recreation. When the Activity restarts, remembered state is gone for good.
What Triggers Recreation
Rotation, language switches, and dark-mode toggles are configuration changes. Each one tears down and rebuilds your UI from scratch.
Meet rememberSaveable
rememberSaveable works like remember but also saves the value into the saved instance state, so it survives recreation.
var count by rememberSaveable { mutableStateOf(0) }Just Swap the Call
Often the fix is a one-word change: replace remember with rememberSaveable and your counter now keeps its value after rotation.
What Can Be Saved
It saves types that fit in a Bundle out of the box: Int, String, Boolean, and other primitives. Most simple state just works.
var name by rememberSaveable { mutableStateOf("") }Custom Types Need a Saver
For your own classes, give rememberSaveable a Saver that tells it how to store and restore the object as bundle-safe data.
Data Classes Made Easy
For Kotlin data classes you can use the mapSaver or listSaver helpers, or annotate with Parcelize, to make saving simple.
@Parcelize
data class User(val name: String) : ParcelableIt Is Not Forever
rememberSaveable survives rotation and brief backgrounding, but not a full app kill. For permanent data you still need storage.
When to Reach for It
Use rememberSaveable for transient UI state you want to keep through rotation, like a counter, a typed query, or a tab index.
remember vs Saveable
Rule of thumb: use remember for cheap or recomputable values, and rememberSaveable when losing the value on rotation would annoy the user.
Quick Check
Which API keeps state through a screen rotation?
Recap
You learned that rememberSaveable keeps transient UI state alive through rotation and config changes, while remember does not. Nicely done! 🎉
الأسئلة الشائعة
هل درس «rememberSaveable عبر التدوير» مجاني؟
نعم — نص درس «rememberSaveable عبر التدوير» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «rememberSaveable عبر التدوير»؟
حافظ على الحالة أثناء تغييرات الإعدادات تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «rememberSaveable عبر التدوير»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- remember وmutableStateOf
- إعادة التركيب: ما الذي يسبب إعادة الرسم
- بناء عدّاد للنقرات
- rememberSaveable عبر التدوير