0Pricing
Jetpack Compose Academy · درس

تمرير الوسائط بين الشاشات

أرسل البيانات عبر مسار التنقل

تمرير الوسائط بين الشاشات درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Screens Need Data

A detail screen needs to know which item to show. Navigation Compose lets you carry that data along the route itself.

Declare a Placeholder

Add a placeholder in curly braces to a route. It marks where a value will slot in when you navigate.

composable("profile/{userId}") { backStackEntry ->
    ProfileScreen()
}

Define the Argument

List each placeholder in arguments and give it a type. This tells Compose how to parse the value out of the route.

composable(
    "profile/{userId}",
    arguments = listOf(navArgument("userId") { type = NavType.IntType })
) { }

Send the Value

To pass data, build the route string with the real value in place of the placeholder. The receiving screen reads it back out.

navController.navigate("profile/42")

Read It from the Entry

The backStackEntry carries the arguments bundle. Pull your value out by the same name you declared in the route.

composable("profile/{userId}") { entry ->
    val id = entry.arguments?.getInt("userId")
    ProfileScreen(userId = id)
}

Choose the Right NavType

The NavType decides parsing: StringType, IntType, BoolType, and more. Match it to your data so values arrive correctly typed.

Optional Arguments

Use a query-style optional argument with a default value for data that may be missing, like a filter that is not always set.

composable(
    "search?query={query}",
    arguments = listOf(navArgument("query") { defaultValue = "" })
) { }

Pass Small Data Only

Route arguments are for identifiers, not whole objects. Send an id, then load the full data from your repository or ViewModel.

Encode Tricky Values

Strings with slashes or spaces can break a route. URL-encode them before navigating and decode after reading, just like a real URL.

Let the ViewModel Read It

A ViewModel can grab arguments from SavedStateHandle, so your screen stays clean and survives recreation with the right data.

class ProfileViewModel(state: SavedStateHandle) {
    val userId: Int = checkNotNull(state["userId"])
}

Keep Argument Names Aligned

The placeholder, the navArgument, and the lookup key must all use the same name. A mismatch returns null instead of your value.

Quick Check

How should you send a complex item to a detail screen?

Recap

You can now pass data by adding a placeholder to a route, typing it with navArgument, and reading it back from the back stack entry. 📦

الأسئلة الشائعة

هل درس «تمرير الوسائط بين الشاشات» مجاني؟

نعم — نص درس «تمرير الوسائط بين الشاشات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «تمرير الوسائط بين الشاشات»؟

أرسل البيانات عبر مسار التنقل تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «تمرير الوسائط بين الشاشات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ‏NavController وNavHost
  2. وجهات Composable والمسارات
  3. تمرير الوسائط بين الشاشات
  4. مكدس الرجوع والروابط العميقة
← العودة إلى Jetpack Compose Academy