قطعه

برنامه خود را به چندین صفحه مستقل که درون یک Activity میزبانی می‌شوند، تقسیم کنید.
آخرین به‌روزرسانی انتشار پایدار کاندیدای انتشار انتشار بتا انتشار آلفا
۱۳ آگوست ۲۰۲۵ ۱.۸.۹ - - -

اعلام وابستگی‌ها

برای افزودن وابستگی به Fragment، باید مخزن Google Maven را به پروژه خود اضافه کنید. برای اطلاعات بیشتر، مخزن Maven گوگل را مطالعه کنید.

وابستگی‌های مربوط به مصنوعات مورد نیاز خود را در فایل build.gradle برای برنامه یا ماژول خود اضافه کنید:

شیار

dependencies {
    def fragment_version = "1.8.9"

    // Java language implementation
    implementation "androidx.fragment:fragment:$fragment_version"
    // Kotlin
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    // Compose
    implementation "androidx.fragment:fragment-compose:$fragment_version"
    // Testing Fragments in Isolation
    debugImplementation "androidx.fragment:fragment-testing-manifest:$fragment_version"
    androidTestImplementation "androidx.fragment:fragment-testing:$fragment_version"
}

کاتلین

dependencies {
    val fragment_version = "1.8.9"

    // Java language implementation
    implementation("androidx.fragment:fragment:$fragment_version")
    // Kotlin
    implementation("androidx.fragment:fragment-ktx:$fragment_version")
    // Compose
    implementation("androidx.fragment:fragment-compose:$fragment_version")
    // Testing Fragments in Isolation
    debugImplementation("androidx.fragment:fragment-testing:$fragment_version")
}

برای اطلاعات بیشتر در مورد وابستگی‌ها، به «افزودن وابستگی‌های ساخت» مراجعه کنید.

بازخورد

بازخورد شما به بهبود Jetpack کمک می‌کند. اگر مشکلات جدیدی کشف کردید یا ایده‌هایی برای بهبود این کتابخانه دارید، به ما اطلاع دهید. لطفاً قبل از ایجاد یک کتابخانه جدید، نگاهی به مشکلات موجود در این کتابخانه بیندازید. می‌توانید با کلیک بر روی دکمه ستاره، رأی خود را به یک مشکل موجود اضافه کنید.

ایجاد یک مسئله جدید

برای اطلاعات بیشتر به مستندات ردیاب مشکل مراجعه کنید.

نسخه ۱.۸

نسخه ۱.۸.۹

۱۳ آگوست ۲۰۲۵

androidx.fragment:fragment-*:1.8.9 منتشر شد. نسخه ۱.۸.۹ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد لغو یک حرکت پیش‌بینی‌کننده‌ی بازگشت که عملیات پنهان شدن را اجرا می‌کند، باعث شود حرکت بعدی هنگام استفاده از انیماتورها به درستی متحرک‌سازی نشود، برطرف شد. ( I0a400 ، b/384765586 )
  • خطایی که باعث می‌شد ترکیبی از setMaxLifecycle و popBackStack نتواند قطعه بالایی را به RESUMED منتقل کند، برطرف شد. ( I3448b ، b/406127576 )

نسخه ۱.۸.۸

۴ ژوئن ۲۰۲۵

androidx.fragment:fragment-*:1.8.8 منتشر شد. نسخه ۱.۸.۸ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد FragmentManager هنگام تلاش برای ذخیره وضعیت Fragmentهایی که با setMaxLifecycle(Lifecycle.State.INITIALIZED) اضافه شده بودند، از کار بیفتد، برطرف شد. این Fragmentها، از آنجایی که هرگز از طریق onCreate() اجرا نمی‌شوند، دیگر هیچ وضعیتی ذخیره یا onSaveInstanceState() فراخوانی نمی‌شود. ( I6e37a )

نسخه ۱.۸.۷

۲۰ مه ۲۰۲۵

androidx.fragment:fragment-*:1.8.7 منتشر شد. نسخه ۱.۸.۷ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد FragmentManager پس از عملیات pop و replace در همان فریم، در وضعیت مناسب قرار نگیرد و باعث خرابی همزمان با pop کردن backstack از طریق popBackStack یا حرکت پیش‌بینی‌کننده‌ی back شود، برطرف شد ( I50ad1 )
  • مشکل از کار افتادن برنامه که به دلیل استفاده از AndroidX Transitions ایجاد می‌شد و باعث می‌شد تراکنش‌های متوالی و سریع قطعه کد، یک گذار شروع نشده را لغو کنند و کتابخانه AndroidX Transition به درستی وضعیت گذار را پاک نمی‌کرد، برطرف شد. (به b/414612221 مراجعه کنید). ( Ib5235 )

نسخه ۱.۸.۶

۱۲ فوریه ۲۰۲۵

androidx.fragment:fragment-*:1.8.6 منتشر شد. نسخه ۱.۸.۶ شامل این کامیت‌ها است.

رفع اشکالات

  • تابع setOnApplyWindowInsetsListener در FragmentContainerView اکنون یک شنونده تهی (null listener) می‌گیرد که با آنچه چارچوب اجازه می‌دهد مطابقت دارد ( I575f0 ، b/282790626 ).

نسخه ۱.۸.۵

۳۰ اکتبر ۲۰۲۴

androidx.fragment:fragment-*:1.8.5 منتشر شد. نسخه ۱.۸.۵ شامل این کامیت‌ها است.

رفع اشکالات

  • خطای IllegalStateException که توسط saveBackStack و تنها پس از لغو یا قطع شدن یک حرکت Predictive Back ایجاد می‌شد، برطرف شد. ( I3387d ، b/342419080 )

نسخه ۱.۸.۴

۲ اکتبر ۲۰۲۴

androidx.fragment:fragment-*:1.8.4 منتشر شد. نسخه ۱.۸.۴ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد فشردن سریع دکمه بازگشت سیستم یا انجام سریع ژست‌های حرکتی بازگشت، باعث از کار افتادن Fragmentها هنگام استفاده از Androidx Transitions شود، برطرف شد. ( Ibc038 ، b/364804225 )
  • مشکلی در قطعه کدها که باعث می‌شد قطع یک حرکت پیش‌بینی‌کننده‌ی بازگشت، مدیر قطعه کد را به حالت نامشخصی ببرد و حتی قطعه‌ی اشتباهی را نمایش دهد، برطرف شد. ( If82e2 , b/338624457 )
  • خطای UninitializedPropertyAccessException در AndroidFragment هنگام تعویض پویای کلاسی که نمونه AndroidFragment شما از آن استفاده می‌کند، برطرف شد. ( I12dea )

نسخه ۱.۸.۳

۴ سپتامبر ۲۰۲۴

androidx.fragment:fragment-*:1.8.3 منتشر شد. نسخه ۱.۸.۳ شامل این کامیت‌ها است.

رفع اشکالات

  • FragmentManager اکنون هنگام مدیریت ژست Predictive Back، عملیات در حال انتظار را به درستی در نظر می‌گیرد. این باید تضمین کند که انجام یک بازگشت سیستمی دیگر باعث خطای IndexOutOfBoundsException نمی‌شود. ( I9ba32 , b/342316801 )
  • اگر AndroidFragment به ترکیب اضافه شود، در حالی که وضعیت activity/fragment حاوی آن از قبل ذخیره شده است، دیگر از کار نمی‌افتد. ( I985e9 , b/356643968 )

نسخه ۱.۸.۲

۲۴ ژوئیه ۲۰۲۴

androidx.fragment:fragment-*:1.8.2 منتشر شد. نسخه ۱.۸.۲ شامل این کامیت‌ها است.

رفع اشکالات

  • AndroidFragment اکنون به درستی مواردی را که قطعه والد در پشته قطعه قرار می‌گیرد، مدیریت می‌کند و از بروز مشکل «نمایی برای شناسه پیدا نشد» هنگام بازگشت به آن قطعه جلوگیری می‌کند. ( I94608 )
  • قطعاتی که از طریق متد FragmentTransaction.add که یک ViewGroup می‌گیرد، اضافه می‌شوند، اکنون قبل از رفتن به onStart() منتظر onContainerAvailable می‌مانند. این موضوع کاربران آن API، مانند AndroidFragment را تحت تأثیر قرار می‌دهد، که اکنون منتظر می‌ماند تا AndroidFragment قبل از انتقال آن از طریق onStart() دوباره ترکیب را وارد کند. ( I94608 )

نسخه ۱.۸.۱

۲۶ ژوئن ۲۰۲۴

androidx.fragment:fragment-*:1.8.1 منتشر شد. نسخه ۱.۸.۱ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد قطعات بدون کانتینر هنگام شروع یک حرکت پیش‌بینی‌کننده‌ی بازگشت، بلافاصله DESTROYED برطرف شد. اکنون آنها تا پس از تکمیل حرکت، در حالت CREATED نگه داشته می‌شوند. ( If6b83 , b/345244539 )

نسخه ۱.۸.۰

۱۲ ژوئن ۲۰۲۴

androidx.fragment:fragment-*:1.8.0 منتشر شد. نسخه ۱.۸.۰ شامل این کامیت‌ها است.

تغییرات مهم از زمان ۱.۷.۰

  • مصنوع fragment-compose اکنون حاوی یک AndroidFragment Composable است که امکان اضافه کردن fragmentها به سلسله مراتب Compose را از طریق نام کلاس fragment فراهم می‌کند. این کلاس به طور خودکار ذخیره و بازیابی وضعیت Fragment را مدیریت می‌کند. این باید به عنوان جایگزینی مستقیم برای رویکرد توصیه شده قبلی یعنی استفاده از AndroidViewBinding برای inflate کردن یک Fragment استفاده شود.
  • تابع فراخوانی onBackStackChangeCancelled در رابط OnBackStackChangedListener از FragmentManager اکنون به عنوان بخشی از عملیات اجرایی در FragmentManager اجرا می‌شود و آن را به زمان‌بندی تابع فراخوانی onBackStackChangeCommitted نزدیک‌تر می‌کند.

نسخه ۱.۸.۰-rc01

۲۹ مه ۲۰۲۴

androidx.fragment:fragment-*:1.8.0-rc01 منتشر شد. نسخه 1.8.0-rc01 شامل این کامیت‌ها است.

رفع اشکالات

  • تابع فراخوانی onBackStackChangeCancelled در رابط FragmentManagers OnBackStackChangedListener اکنون به عنوان بخشی از عملیات اجرایی در FragmentManager اجرا می‌شود و آن را به زمان‌بندی تابع فراخوانی onBackStackChangeCommitted نزدیک‌تر می‌کند. ( I5ebfb , b/332916112 )

نسخه ۱.۸.۰-بتا۰۱

۱۴ مه ۲۰۲۴

androidx.fragment:fragment-*:1.8.0-beta01 منتشر شد. نسخه 1.8.0-beta01 شامل این کامیت‌ها است.

رفع اشکالات

  • از قطعه 1.7.1 : پیش‌گویی بازگشتی اکنون فقط برای تراکنش‌هایی اجرا می‌شود که در آن‌ها تمام قطعات دارای Animator یا Seekable Androidx Transition باشند. این مشکل را برطرف می‌کند که لغو یک تراکنش نیمه‌قابل Seek باعث نمایش صفحه سیاه می‌شد. ( I43037 ، b/339169168 )

نسخه ۱.۸.۰-آلفا۰۲

۱۷ آوریل ۲۰۲۴

androidx.fragment:fragment-*:1.8.0-alpha02 منتشر شد. نسخه 1.8.0-alpha02 شامل این کامیت‌ها است.

رفع اشکالات

  • از قطعه 1.7.0-rc02 : لاگ‌هایی اضافه شده که نشان می‌دهد چرا تنظیم یک sharedElement بدون هیچ انتقال دیگری اجرا نمی‌شود. ( Iec48e )
  • از قطعه 1.7.0-rc02 : اشکالی که باعث می‌شد اگر یک عنصر مشترک غیرقابل جستجو به تراکنش‌هایی اضافه شود که در آن‌ها همه انتقال‌های دیگر قابل جستجو بودند، خرابی رخ می‌داد، برطرف شد. اکنون تراکنش به درستی غیرقابل جستجو در نظر گرفته می‌شود. ( I18ccd )

نسخه ۱.۸.۰-آلفا۰۱

۳ آوریل ۲۰۲۴

androidx.fragment:fragment-*:1.8.0-alpha01 منتشر شد. نسخه 1.8.0-alpha01 شامل این کامیت‌ها است.

ویژگی‌های جدید

  • AndroidFragment Composable جدید امکان اضافه کردن fragmentها به سلسله مراتب Compose را از طریق نام کلاس fragment فراهم می‌کند. این کلاس به طور خودکار ذخیره و بازیابی وضعیت Fragment را مدیریت می‌کند. این کامپوننت می‌تواند به عنوان جایگزینی مستقیم برای AndroidViewBinding Composable ( b/312895363 , Icf841 ) استفاده شود.

تغییرات مستندات

  • مستندات مربوط به APIهای OnBackStackChangedListener به‌روزرسانی شد تا مشخص شود چه زمانی فراخوانی می‌شوند و چگونه باید استفاده شوند. ( I0bfd9 )

به‌روزرسانی وابستگی

نسخه ۱.۷

نسخه ۱.۷.۱

۱۴ مه ۲۰۲۴

androidx.fragment:fragment-*:1.7.1 منتشر شد. نسخه ۱.۷.۱ شامل این کامیت‌ها است.

رفع اشکالات

  • پیش‌گویی بازگشتی اکنون فقط برای تراکنش‌هایی اجرا می‌شود که در آن‌ها تمام قطعات دارای Animator یا Seekable Androidx Transition باشند. این مشکل را برطرف می‌کند که لغو یک تراکنش نیمه‌قابل Seek باعث نمایش صفحه خالی می‌شد. ( I43037 ، b/339169168 )

نسخه ۱.۷.۰

۱ مه ۲۰۲۴

androidx.fragment:fragment-*:1.7.0 منتشر شد. نسخه ۱.۷.۰ شامل این کامیت‌ها است.

پشتیبانی از ژست‌های حرکتی پیش‌بینی‌کننده برای بازگشت

  • فرگمنت‌ها اکنون از قابلیت پیش‌بینی بازگشت درون‌برنامه‌ای هنگام استفاده از Animator یا هنگام استفاده از AndroidX Transition 1.5.0 پشتیبانی می‌کنند. این به کاربران اجازه می‌دهد تا قبل از تصمیم‌گیری برای انجام تراکنش از طریق تکمیل حرکت یا لغو، با جستجوی Animator/Transition شما، از حرکت بازگشت برای دیدن فرگمنت قبلی استفاده کنند.
سیستم انتقال منبع XML پشتیبانی از پیش‌بینی بازگشت
Animation R.anim خیر
Animator R.animator بله
Transition چارچوب R.transition خیر
Transition AndroidX با انتقال ۱.۴.۱ یا کمتر R.transition خیر
Transition AndroidX با انتقال 1.5.0 R.transition بله

اگر پس از انتخاب ژست پیش‌بینی بازگشت ، مشکلی در پشتیبانی از Predictive Back در Fragments مشاهده کردید، لطفاً با یک پروژه نمونه که مشکل شما را بازتولید می‌کند، مشکل خود را در Fragment ثبت کنید . می‌توانید Predictive Back را با استفاده از FragmentManager.enabledPredictiveBack(false) در onCreate() از Activity خود غیرفعال کنید.

FragmentManager.OnBackStackChangedListener() اکنون onBackStackChangeProgressed() و onBackStackChangeCancelled() را به ترتیب برای دریافت رویدادهای پیش‌بینی‌کننده‌ی پیشرفت بازگشتی و لغو شده فراهم می‌کند.

مصنوع قطعه قطعه

یک مصنوع جدید fragment-compose ایجاد شده است که بر پشتیبانی از برنامه‌هایی تمرکز دارد که در حال گذار از معماری مبتنی بر Fragment به معماری کاملاً مبتنی بر Compose هستند.

اولین ویژگی موجود در این محصول جدید، یک متد افزونه‌ی content روی Fragment است که با ایجاد یک ComposeView برای شما و تنظیم صحیح ViewCompositionStrategy ، استفاده از Compose را برای رابط کاربری یک فرگمنت منفرد آسان‌تر می‌کند.

  class ExampleFragment : Fragment() {

      override fun onCreateView(
          inflater: LayoutInflater,
          container: ViewGroup?,
          savedInstanceState: Bundle?
      ) = content {
          // Write your @Composable content here
          val viewModel: ExampleViewModel = viewModel()

          // or extract it into a separate, testable method
          ExampleComposable(viewModel)
      }
  }

نسخه ۱.۷.۰-rc02

۱۷ آوریل ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-rc02 منتشر شد. نسخه 1.7.0-rc02 شامل این کامیت‌ها است.

رفع اشکالات

  • لاگ‌هایی اضافه شد تا نشان دهد چرا تنظیم یک sharedElement بدون هیچ انتقال دیگری اجرا نمی‌شود. ( Iec48e )
  • اشکالی که باعث می‌شد اگر یک عنصر مشترک غیرقابل جستجو به تراکنش‌هایی اضافه شود که همه انتقال‌های دیگر قابل جستجو بودند، دچار مشکل می‌شد، برطرف شد. اکنون تراکنش به درستی غیرقابل جستجو در نظر گرفته می‌شود. ( I18ccd )

نسخه ۱.۷.۰-rc01

۳ آوریل ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-rc01 منتشر شد. نسخه 1.7.0-rc01 شامل این کامیت‌ها است.

به‌روزرسانی وابستگی

نسخه ۱.۷.۰-بتا۰۱

۲۰ مارس ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-beta01 منتشر شد. نسخه 1.7.0-beta01 شامل این کامیت‌ها است.

تغییرات API

  • FragmentHostCallback اکنون به زبان کاتلین نوشته شده است، به طوری که مقدار nullability نوع ژنریک Host با مقدار nullability نوع بازگشتی onGetHost() مطابقت داشته باشد ( I40af5 ).

رفع اشکالات

  • مشکلی که باعث می‌شد هنگام اجرای یک دستور Predictive Back روی قطعه‌ای که در کانتینر نیست، آن قطعه هرگز از بین نرود، برطرف شد. اکنون قطعه بلافاصله به حالت نهایی منتقل می‌شود. ( Ida0d9 )
  • مشکلی در Fragments که در آن قطع انتقال‌های ورودی با یک حرکت پیش‌بینی‌کننده‌ی بازگشت، نمای ورودی را از بین می‌برد و یک صفحه خالی باقی می‌گذاشت، برطرف شد. ( Id3f22 ، b/319531491 )

نسخه ۱.۷.۰-آلفا۱۰

۷ فوریه ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-alpha10 منتشر شد. نسخه 1.7.0-alpha10 شامل این کامیت‌ها است.

رفع اشکالات

  • مشکل شناخته‌شده در نسخه قبلی Fragment که در آن با استفاده از پشتیبانی Predictive Back از Fragment برای Animator یا AndroidX Transition، اگر هیچ FragmentManager.OnBackStackChangedListener از طریق addOnBackStackChangedListener اضافه نشده بود، Fragments NullPointerException از handleOnBackProgressed ارسال می‌کرد، برطرف شد. ( I7c835 )

نسخه ۱.۷.۰-آلفا۰۹

۲۴ ژانویه ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-alpha09 منتشر شد. نسخه 1.7.0-alpha09 شامل این کامیت‌ها است.

مصنوع قطعه قطعه

یک مصنوع جدید fragment-compose ایجاد شده است که بر پشتیبانی از برنامه‌هایی تمرکز دارد که در حال گذار از معماری مبتنی بر Fragment به معماری کاملاً مبتنی بر Compose هستند.

اولین ویژگی موجود در این محصول جدید، یک متد افزونه‌ی content روی Fragment است که با ایجاد یک ComposeView برای شما و تنظیم صحیح ViewCompositionStrategy ، استفاده از Compose را برای رابط کاربری یک فرگمنت واحد آسان‌تر می‌کند. ( 561cb7 , b/258046948 )

class ExampleFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ) = content {
        // Write your @Composable content here
        val viewModel: ExampleViewModel = viewModel()

        // or extract it into a separate, testable method
        ExampleComposable(viewModel)
    }
}

ویژگی‌های جدید

  • FragmentManager.OnBackStackChangedListener() اکنون onBackStackChangeProgressed() و onBackStackChangeCancelled() را به ترتیب برای دریافت رویدادهای پیش‌بینی‌کننده‌ی پیشرفت به عقب و لغو شده فراهم می‌کند. ( 214b87 )

مشکل شناخته شده

  • هنگام استفاده از پشتیبانی Predictive Back در Fragment برای Animator یا AndroidX Transition، اگر هیچ FragmentManager.OnBackStackChangedListener از طریق addOnBackStackChangedListener اضافه نشده باشد، Fragments یک NullPointerException از handleOnBackProgressed ارسال می‌کند. اضافه کردن دستی یک شنونده (listener) می‌تواند این مشکل را حل کند. در نسخه بعدی Fragments، راه حلی برای این مشکل ارائه خواهد شد.

نسخه ۱.۷.۰-آلفا۰۸

۱۰ ژانویه ۲۰۲۴

androidx.fragment:fragment-*:1.7.0-alpha08 منتشر شد. نسخه 1.7.0-alpha08 شامل این کامیت‌ها است.

تمیز کردن

  • راه‌حل جایگزین برای کتابخانه‌ی Transition که در Transition 1.5.0-alpha06 اصلاح شده بود، حذف شد. ( I04356 )

نسخه ۱.۷.۰-آلفا۰۷

۲۹ نوامبر ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha07 منتشر شد. نسخه 1.7.0-alpha07 شامل این کامیت‌ها است.

رفع اشکالات

  • خطای NullPointerException که به دلیل تنظیم یک گذار عنصر مشترک و عدم تنظیم یک گذار ورود/خروج ایجاد می‌شد، برطرف شد ( I8472b )
  • از قطعه کد 1.6.2 : وقتی قطعه کد یک FragmentContainerView فشرده می‌شود، حالت‌های آن مانند FragmentManager ، Host و id اکنون در فراخوانی onInflate قابل دسترسی هستند. ( I1e44c ، b/307427423 )
  • از قطعه کد 1.6.2 : هنگام استفاده از clearBackStack برای حذف مجموعه‌ای از قطعه کدها، هر ViewModel قطعه کد تو در تو، با پاک شدن ViewModels قطعه کد والد، پاک خواهد شد. ( I6d83c ، b/296173018 )

نسخه ۱.۷.۰-alpha06

۴ اکتبر ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha06 منتشر شد. نسخه 1.7.0-alpha06 شامل این کامیت‌ها است.

به‌روزرسانی وابستگی

  • Fragments به‌روزرسانی شده است تا به API جدید animateToStart که در Transition 1.5.0-alpha04 اضافه شده است، وابسته باشد.

نسخه ۱.۷.۰-آلفا۰۵

۲۰ سپتامبر ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha05 منتشر شد. نسخه 1.7.0-alpha05 شامل این کامیت‌ها است.

ویژگی‌های جدید

  • اکنون فرگمنت‌ها هنگام استفاده از Androidx Transitions از قابلیت بازگشت پیش‌بینی‌کننده پشتیبانی می‌کنند. این به شما امکان می‌دهد قبل از تصمیم‌گیری برای انجام یا لغو تراکنش از طریق ژست تکمیل‌شده، از ژست بازگشت برای جستجوی فرگمنت قبلی با Androidx Transition سفارشی خود استفاده کنید. برای فعال کردن این ویژگی باید به نسخه Transition 1.5.0-alpha03 اعتماد کنید. ( Ib49b4 ، b/285175724 )

مشکلات شناخته شده

  • در حال حاضر مشکلی وجود دارد که پس از لغو یک باره‌ی حرکت برگشت با یک انتقال، دفعه‌ی بعد که حرکت برگشت را شروع می‌کنید، انتقال اجرا نمی‌شود و باعث نمایش صفحه‌ی خالی می‌شود. این مشکل می‌تواند ناشی از مشکلی در کتابخانه‌ی انتقال باشد. ( b/300157785 ). اگر این مشکل را مشاهده کردید، لطفاً با یک پروژه‌ی نمونه که مشکل شما را بازتولید می‌کند ، در Fragment یک مشکل ایجاد کنید . می‌توانید با استفاده از FragmentManager.enabledPredictiveBack(false) در onCreate() از Activity خود، قابلیت پیش‌بینی بازگشت را غیرفعال کنید.

نسخه ۱.۷.۰-آلفا۰۴

۶ سپتامبر ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha04 منتشر شد. نسخه 1.7.0-alpha04 شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که هنگام لغو یک حرکت پیش‌بینی‌کننده‌ی بازگشت وجود داشت و در آن قطعات نمی‌توانستند به حالت چرخه‌ی حیات صحیح برسند، برطرف شد. ( I7cffe ، b/297379023 )
  • مشکل رگرسیون که در آن انیمیشن‌ها اجازه اجرا شدن با Transitionها را داشتند، برطرف شد ( I59f36 )
  • مشکلی که هنگام استفاده از Predictive Back با قطعات وجود داشت و در آن تلاش برای بازگشت سریع دو بار پشت سر هم روی قطعه یکی مانده به آخر در پشته پشتی باعث خرابی می‌شد، برطرف شد. ( Ifa1a4 )

نسخه ۱.۷.۰-آلفا۰۳

۲۳ آگوست ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha03 منتشر شد. نسخه 1.7.0-alpha03 شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که هنگام استفاده از بازگشت پیش‌بینی‌شده با قطعات (Fragments) وجود داشت و باعث می‌شد اولین قطعه در پشته بازگشت مدیر قطعه نادیده گرفته شود و فعالیت هنگام استفاده از بازگشت سیستم از طریق پیمایش ۳ دکمه‌ای یا حرکت بازگشت پیش‌بینی‌شده به پایان برسد، برطرف شد. ( I0664b ، b/295231788 )

نسخه ۱.۷.۰-آلفا۰۲

۹ آگوست ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha02 منتشر شد. نسخه 1.7.0-alpha02 شامل این کامیت‌ها است.

رفع اشکالات

  • هنگام استفاده از Fragments با ژست‌های حرکتی پیش‌بینانه‌ی Back از API 34، اگر از سیستم انتقالی استفاده می‌کنید که از جستجو ( Animations ، Transitions ) پشتیبانی نمی‌کند یا اصلاً هیچ انتقالی ندارد، Fragments اکنون منتظر می‌ماند تا ژست حرکتی قبل از اجرای عمل Back کامل شود. ( I8100c )

نسخه ۱.۷.۰-آلفا۰۱

۷ ژوئن ۲۰۲۳

androidx.fragment:fragment-*:1.7.0-alpha01 منتشر شد. این نسخه در یک شاخه داخلی توسعه داده شده است.

ویژگی‌های جدید

  • اکنون فرگمنت‌ها هنگام استفاده از Animator از بازگشت درون‌برنامه‌ای پیش‌بینی‌کننده پشتیبانی می‌کنند. این به شما امکان می‌دهد قبل از تصمیم‌گیری برای انجام تراکنش از طریق حرکت تکمیل‌شده یا لغو، از حرکت بازگشت برای دیدن فرگمنت قبلی با Animator سفارشی خود استفاده کنید. همچنین می‌توانید این رفتار جدید را با استفاده از enablePredictiveBack() آزمایشی و ارسال false غیرفعال کنید.

نسخه ۱.۶

نسخه ۱.۶.۲

۱ نوامبر ۲۰۲۳

androidx.fragment:fragment-*:1.6.2 منتشر شد. نسخه ۱.۶.۲ شامل این کامیت‌ها است.

رفع اشکالات

  • وقتی فرگمنت یک FragmentContainerView متورم می‌شود، حالت‌های آن مانند FragmentManager ، Host و id اکنون در فراخوانی onInflate قابل دسترسی هستند. ( I1e44c ، b/307427423 )
  • هنگام استفاده از clearBackStack برای حذف مجموعه‌ای از قطعات، اکنون هر ViewModel قطعه‌ی تو در تو، با پاک شدن ViewModels های قطعه‌ی والد، پاک خواهد شد. ( I6d83c ، b/296173018 )

نسخه ۱.۶.۱

۲۶ ژوئیه ۲۰۲۳

androidx.fragment:fragment-*:1.6.1 منتشر شد. نسخه ۱.۶.۱ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد حالت ذخیره‌شده هنگام توقف فعالیت اما عدم تخریب آن، حتی پس از انتقال نمونه قطعه به حالت RESUMED ، به اشتباه ذخیره شود، برطرف شد. این امر باعث می‌شد اگر آن نمونه قطعه در پشته پشتی باشد، هنگام استفاده از API پشته‌های پشتی چندگانه برای ذخیره و بازیابی آن قطعه، حالت ذخیره‌شده دوباره استفاده شود. ( I71288 ، b/246289075 )

به‌روزرسانی وابستگی

  • فرگمنت اکنون به Activity نسخه ۱.۷.۲ وابسته است. این مشکل را برطرف می‌کند که کاربران کاتلین نمی‌توانستند ComponentDialog بدون وابستگی صریح به Activity گسترش دهند. ( b/287509323 )

نسخه ۱.۶.۰

۷ ژوئن ۲۰۲۳

androidx.fragment:fragment-*:1.6.0 منتشر شد. نسخه ۱.۶.۰ شامل این کامیت‌ها است.

تغییرات مهم از زمان ۱.۵.۰

  • وضعیت ذخیره‌شده‌ی Fragment s به‌طور کامل بین وضعیت کتابخانه‌ی خصوصی (کلاس‌های سفارشی Parcelable ) و وضعیت ارائه‌شده توسط توسعه‌دهنده تقسیم شده است، که اکنون همیشه در یک Bundle ذخیره می‌شود که امکان تعیین دقیق منشأ وضعیت یک Fragment را فراهم می‌کند.
  • رابط FragmentManager.OnBackStackChangedListener با دو فراخوانی مجدد onBackStackChangeStarted و onBackStackChangeCommitted گسترش یافته است که به ترتیب با هر Fragment درست قبل از اضافه/حذف شدن از پشته پشتی قطعه و درست پس از انجام تراکنش فراخوانی می‌شوند.
  • FragmentStrictMode یک WrongNestedHierarchyViolation جدید اضافه کرده است که تشخیص می‌دهد چه زمانی یک قطعه کد فرزند درون سلسله مراتب View والد خود تودرتو شده است، اما به childFragmentManager والد اضافه نشده است.
  • APIهای Fragment و FragmentManager که Intent یا IntentSender را دریافت می‌کنند، اکنون به درستی با @NonNull حاشیه‌نویسی شده‌اند تا از ارسال مقدار null جلوگیری شود، زیرا مقدار null همیشه بلافاصله APIهای فریم‌ورک اندروید مربوطه را که این متدها فراخوانی می‌کنند، از کار می‌اندازد.
  • DialogFragment اکنون از طریق API requireComponentDialog() دسترسی به ComponentDialog زیرین را فراهم می‌کند.
  • فرگمنت اکنون به Lifecycle 2.6.1 وابسته است.
  • فرگمنت اکنون به SavedState 1.2.1 وابسته است.
  • اکنون Fragment به ProfileInstaller 1.3.0 وابسته است.
  • مصنوع fragment-testing-manifest ورودی‌های manifest را از بقیه اجزای fragment-testing جدا می‌کند. این بدان معناست که می‌توانید موارد زیر را انجام دهید:

    debugImplementation("androidx.fragment:fragment-testing-manifest:X.Y.Z")
    androidTestImplementation("androidx.fragment:fragment-testing:X.Y.Z")
    

    این کار از تداخل ناشی از انحراف نسخه بین fragment-testing و androidx.test جلوگیری می‌کند.

نسخه ۱.۶.۰-rc01

۱۰ مه ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-rc01 منتشر شد. نسخه 1.6.0-rc01 شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد ActivityResult ها با کد درخواست نادرست ارسال شوند، زمانی که چندین درخواست startActivityForResult به صورت متوالی ارسال می‌شدند، برطرف شد. ( If0b9d , b/249519359 )
  • مشکلی که باعث می‌شد توابع برگشتی onBackStackChangeListener برای تراکنش‌هایی ارسال شوند که در واقع پشته پشتی را تغییر نمی‌دادند، اگر با تراکنش‌هایی که پشته پشتی را تغییر می‌دهند، مخلوط می‌شدند، برطرف شد. ( I0eb5c , b/279306628 )

نسخه ۱.۶.۰-بتا۰۱

۱۹ آوریل ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-beta01 منتشر شد. نسخه 1.6.0-beta01 شامل این کامیت‌ها است.

رفع اشکالات

  • استفاده از postponeEnterTransition ‎ به همراه یک timeout و سپس جایگزینی قطعه به تعویق افتاده، دیگر منجر به نشت قطعه به تعویق افتاده نمی‌شود. ( I2ec7d , b/276375110 )
  • فراخوانی‌های جدید onBackStackChangeStarted و onBackStackChangeCommitted اکنون فقط یک قطعه را یک بار ارسال می‌کنند، حتی اگر چندین تراکنش حاوی قطعه یکسانی باشند. ( Ic6b69 )

نسخه ۱.۶.۰-آلفا۰۹

۵ آوریل ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-alpha09 منتشر شد. نسخه 1.6.0-alpha09 شامل این کامیت‌ها است.

تغییرات API

  • DialogFragment اکنون از طریق API requireComponentDialog() دسترسی به ComponentDialog زیرین را فراهم می‌کند. ( I022e3 , b/234274777 )
  • APIهای قطعه کد commitNow() ، executePendingTransactions() و popBackStackImmediate() با @MainThread حاشیه‌نویسی شده‌اند، به این معنی که اکنون همه آنها وقتی از نخ اصلی فراخوانی نشوند، به جای انتظار برای شکست در زمان اجرا، خطاهای ساخت را ایجاد می‌کنند. ( Ic9665 ، b/236538905 )

رفع اشکالات

  • اشکالی در FragmentManager که ذخیره و بازیابی در یک فریم می‌توانست باعث خرابی شود، برطرف شد. ( Ib36af ، b/246519668 )
  • فراخوانی‌های OnBackStackChangedListener onBackStackChangeStarted و onBackStackChangeCommitted اکنون فقط زمانی اجرا می‌شوند که پشته FragmentManager تغییر کند. ( I66055 ، b/274788957 )

نسخه ۱.۶.۰-آلفا۰۸

۲۲ مارس ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-alpha08 منتشر شد. نسخه 1.6.0-alpha08 شامل این کامیت‌ها است.

تغییر رفتار

  • زمان‌بندی فراخوانی OnBackStackChangedListener.onBackStackChangeCommited طوری تنظیم شده است که قبل از اجرای عملیات قطعه قطعه اجرا شود. این تضمین می‌کند که هرگز قطعه قطعه شده‌ای به فراخوانی برگشتی ارسال نشود. ( I66a76 , b/273568280 )

رفع اشکالات

  • از قطعه 1.5.6 : مشکلی که باعث می‌شد فراخوانی clearFragmentResultListener درون یک setFragmentResultListener در صورتی که Lifecycle از قبل STARTED باشد و نتیجه‌ای در دسترس باشد، کار نکند، برطرف شد ( If7458 )

به‌روزرسانی‌های وابستگی

نسخه ۱.۶.۰-آلفا۰۷

۸ مارس ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-alpha07 منتشر شد. نسخه 1.6.0-alpha07 شامل این کامیت‌ها است.

رفع اشکالات

  • از قطعه 1.5.6 : مشکلی که باعث می‌شد حذف هر قطعه‌ای، چه آیتم‌های منو را اضافه کرده باشد و چه نه، منوی فعالیت را نامعتبر کند، برطرف شد. ( 50f098 , b/244336571 )

نسخه ۱.۶.۰-alpha06

۲۲ فوریه ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-alpha06 منتشر شد. نسخه 1.6.0-alpha06 شامل این کامیت‌ها است.

تغییر رفتار

  • تابع فراخوانی جدید onBackStackChangedStarted روی onBackStackChangedListener مربوط به FragmentManager ، اکنون قبل از اینکه قطعات شروع به حرکت به حالت‌های هدف خود کنند، اجرا خواهد شد. ( I34726 )

نسخه ۱.۶.۰-آلفا۰۵

۸ فوریه ۲۰۲۳

androidx.fragment:fragment-*:1.6.0-alpha05 منتشر شد. نسخه 1.6.0-alpha05 شامل این کامیت‌ها است.

ویژگی‌های جدید

  • رابط FragmentManager.OnBackStackChagnedListener اکنون دو تابع فراخوانی اضافی به نام‌های onBackStackChangeStarted و onBackStackChangeCommitted ارائه می‌دهد که امکان اطلاعات بیشتر و کنترل تغییرات پشته در FragmentManager را فراهم می‌کنند. ( Ib7ce5 ، b/238686802 )

تغییرات API

  • APIهای Fragment و FragmentManager که Intent یا IntentSender را دریافت می‌کنند، اکنون به درستی با @NonNull حاشیه‌نویسی شده‌اند تا از ارسال مقدار null جلوگیری شود، زیرا مقدار null همیشه بلافاصله APIهای فریم‌ورک اندروید مربوطه را که این متدها فراخوانی می‌کنند، از کار می‌اندازد ( I06fd4 ).

نسخه ۱.۶.۰-آلفا۰۴

۷ دسامبر ۲۰۲۲

androidx.fragment:fragment-*:1.6.0-alpha04 منتشر شد. نسخه 1.6.0-alpha04 شامل این کامیت‌ها است.

ویژگی‌های جدید

  • FragmentStrictMode یک WrongNestedHierarchyViolation جدید اضافه کرده است که تشخیص می‌دهد چه زمانی یک قطعه کد فرزند درون سلسله مراتب View والد خود تودرتو شده است، اما به childFragmentManager والد اضافه نشده است. ( I72521 ، b/249299268 )

تغییرات رفتاری

  • اکنون فرگمنت‌ها وضعیت SavedStateRegistry خود را قبل از onAttach() بازیابی می‌کنند و اطمینان حاصل می‌کنند که از تمام متدهای چرخه عمر رو به بالا در دسترس است. ( I1e2b1 )

تغییرات API

  • مصنوع fragment-testing-manifest ورودی‌های manifest را از بقیه اجزای fragment-testing جدا می‌کند. این بدان معناست که می‌توانید موارد زیر را انجام دهید:
debugImplementation("androidx.fragment:fragment-testing-manifest:X.Y.Z")
androidTestImplementation("androidx.fragment:fragment-testing:X.Y.Z")

این کار از تداخل ناشی از انحراف نسخه بین fragment-testing و androidx.test جلوگیری می‌کند. ( I8e534 , b/128612536 )

رفع اشکالات

  • از قطعه کد 1.5.5 : قطعه کدها دیگر به اشتباه وضعیت ViewModel را به عنوان بخشی از وضعیت ذخیره شده در رجیستری view ذخیره نمی‌کنند. ( I10d2b , b/253546214 )

نسخه ۱.۶.۰-آلفا۰۳

۵ اکتبر ۲۰۲۲

androidx.fragment:fragment:1.6.0-alpha03 ، androidx.fragment:fragment-ktx:1.6.0-alpha03 و androidx.fragment:fragment-testing:1.6.0-alpha03 منتشر شدند. نسخه 1.6.0-alpha03 شامل این کامیت‌ها است.

تغییرات API

  • کلاس‌هایی که از DialogFragment ارث‌بری می‌کنند، اکنون ملزم به فراخوانی super در overrideهای onDismiss() خود هستند. ( I14798 , b/238928865 )

رفع اشکالات

  • رگرسیون‌های ناشی از ادغام رابط‌های فراخوانی جدید ارائه‌دهنده ( OnConfigurationChangedProvider ، OnMultiWindowModeChangedProvider ، OnTrimMemoryProvider ، OnPictureInPictureModeChangedProvider ) برطرف شد تا اطمینان حاصل شود که قطعات همیشه فراخوانی‌های مناسب را دریافت می‌کنند. ( I9b380 ، I34581 ، ( I8dfe6 ، b/242570955If9d6b ، Id0096 ، I690b3 ، I2cba2 )

نسخه ۱.۶.۰-آلفا۰۲

۲۴ آگوست ۲۰۲۲

androidx.fragment:fragment:1.6.0-alpha02 ، androidx.fragment:fragment-ktx:1.6.0-alpha02 و androidx.fragment:fragment-testing:1.6.0-alpha02 منتشر شدند. نسخه 1.6.0-alpha02 شامل این کامیت‌ها است.

رفع اشکالات

  • از قطعه 1.5.2 : مشکلی که باعث می‌شد اجرای همزمان تراکنش‌های popBackStack() و replace() باعث شود قطعه‌های در حال خروج، Animation / Animator اشتباهی را اجرا کنند، برطرف شد. ( Ib1c07 , b/214835303 )

نسخه ۱.۶.۰-آلفا۰۱

۲۷ ژوئیه ۲۰۲۲

androidx.fragment:fragment:1.6.0-alpha01 ، androidx.fragment:fragment-ktx:1.6.0-alpha01 و androidx.fragment:fragment-testing:1.6.0-alpha01 منتشر شدند. نسخه 1.6.0-alpha01 شامل این کامیت‌ها است.

تغییرات رفتاری

  • وضعیت ذخیره‌شده‌ی Fragment s به‌طور کامل بین وضعیت کتابخانه‌ی خصوصی (کلاس‌های سفارشی Parcelable ) و وضعیت ارائه‌شده توسط توسعه‌دهنده تقسیم شده است، که اکنون همیشه در یک Bundle ذخیره می‌شود که امکان تعیین دقیق منشأ وضعیت یک Fragment را فراهم می‌کند. ( b/207158202 )

رفع اشکالات

  • از قطعه 1.5.1 : رفع مشکل رگرسیون در DialogFragmentCallbacksDetector که در آن استفاده از نسخه lint همراه با AGP 7.4 باعث از کار افتادن lint می‌شد. ( b/237567009 )

به‌روزرسانی وابستگی

نسخه ۱.۵

نسخه ۱.۵.۷

۱۹ آوریل ۲۰۲۳

androidx.fragment:fragment:1.5.7 ، androidx.fragment:fragment-ktx:1.5.7 و androidx.fragment:fragment-testing:1.5.7 منتشر شدند. نسخه ۱.۵.۷ شامل این کامیت‌ها است.

رفع اشکالات

  • استفاده از postponeEnterTransition ‎ به همراه یک timeout و سپس جایگزینی قطعه به تعویق افتاده، دیگر منجر به نشت قطعه به تعویق افتاده نمی‌شود. ( I2ec7d , b/276375110 )

نسخه ۱.۵.۶

۲۲ مارس ۲۰۲۳

androidx.fragment:fragment:1.5.6 ، androidx.fragment:fragment-ktx:1.5.6 و androidx.fragment:fragment-testing:1.5.6 منتشر شدند. نسخه ۱.۵.۶ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد حذف هر Fragment، چه آیتم‌های منو را اضافه کرده باشد و چه نه، منوی فعالیت را نامعتبر کند، برطرف شد. ( 50f098 ، b/244336571 )
  • مشکلی که باعث می‌شد فراخوانی clearFragmentResultListener درون setFragmentResultListener در صورتی که Lifecycle از قبل STARTED باشد و نتیجه‌ای در دسترس باشد، کار نکند، برطرف شد ( If7458 )

نسخه ۱.۵.۵

۷ دسامبر ۲۰۲۲

androidx.fragment:fragment:1.5.5 ، androidx.fragment:fragment-ktx:1.5.5 و androidx.fragment:fragment-testing:1.5.5 منتشر شدند. نسخه ۱.۵.۵ شامل این کامیت‌ها است.

رفع اشکالات

  • قطعات دیگر به اشتباه وضعیت ViewModel را به عنوان بخشی از وضعیت ذخیره شده در رجیستری نما ذخیره نمی‌کنند. ( I10d2b , b/253546214 )

نسخه ۱.۵.۴

۲۴ اکتبر ۲۰۲۲

androidx.fragment:fragment:1.5.4 ، androidx.fragment:fragment-ktx:1.5.4 و androidx.fragment:fragment-testing:1.5.4 منتشر شدند. نسخه ۱.۵.۴ شامل این کامیت‌ها است.

رفع اشکالات

  • خطایی که در آن استفاده از یک FragmentController سفارشی با میزبانی که رابط فراخوانی ارائه دهنده ( OnConfigurationChangedProvider ، OnMultiWindowModeChangedProvider ، OnTrimMemoryProvider ، OnPictureInPictureModeChangedProvider ) را پیاده‌سازی نمی‌کند و فراخوانی تابع dispatch منسوخ شده آن، در ارسال به قطعات فرزند ناموفق بود، برطرف شد. ( I9b380 )

نسخه ۱.۵.۳

۲۱ سپتامبر ۲۰۲۲

androidx.fragment:fragment:1.5.3 ، androidx.fragment:fragment-ktx:1.5.3 و androidx.fragment:fragment-testing:1.5.3 منتشر شدند. نسخه ۱.۵.۳ شامل این کامیت‌ها است.

رفع اشکالات

  • خطایی که باعث می‌شد قطعات موجود در پشته پشتی فراخوانی‌های onMultiWindowModeChanged() ، onPictureInPictureModeChanged() ، onLowMemory() و onConfigurationChanged() را دریافت کنند، برطرف شد. ( I34581 ، I8dfe6 ، b/242570955 )
  • قطعات فرزند تو در تو دیگر چندین فراخوانی onMultiWindowModeChanged() ، onPictureInPictureModeChanged() ، onLowMemory() یا onConfigurationChanged() دریافت نخواهند کرد. ( I690b3 ، Id0096 ، If9d6b ، I2cba2 )

نسخه ۱.۵.۲

۱۰ آگوست ۲۰۲۲

androidx.fragment:fragment:1.5.2 ، androidx.fragment:fragment-ktx:1.5.2 و androidx.fragment:fragment-testing:1.5.2 منتشر شدند. نسخه ۱.۵.۲ شامل این کامیت‌ها است.

رفع اشکالات

  • مشکلی که باعث می‌شد اجرای همزمان تراکنش‌های popBackStack() و replace() باعث شود قطعات خروجی Animation / Animator اشتباهی را اجرا کنند، برطرف شد. ( Ib1c07 , b/214835303 )

نسخه ۱.۵.۱

۲۷ ژوئیه ۲۰۲۲

androidx.fragment:fragment:1.5.1 ، androidx.fragment:fragment-ktx:1.5.1 و androidx.fragment:fragment-testing:1.5.1 منتشر شدند. نسخه ۱.۵.۱ شامل این کامیت‌ها است.

رفع اشکالات

  • رفع مشکل رگرسیون در DialogFragmentCallbacksDetector که در آن استفاده از نسخه lint همراه با AGP 7.4 باعث از کار افتادن lint می‌شد. ( b/237567009 )

به‌روزرسانی وابستگی

نسخه ۱.۵.۰

۲۹ ژوئن ۲۰۲۲

androidx.fragment:fragment:1.5.0 ، androidx.fragment:fragment-ktx:1.5.0 و androidx.fragment:fragment-testing:1.5.0 منتشر شدند. نسخه ۱.۵.۰ شامل این کامیت‌ها است.

تغییرات مهم از زمان ۱.۴.۰

  • یکپارچه‌سازی CreationExtras - Fragment اکنون توانایی ارائه یک ViewModelProvider.Factory بدون وضعیت را از طریق CreationExtras در Lifecycle 2.5.0 دارد.
  • یکپارچه‌سازی دیالوگ کامپوننت - DialogFragment اکنون از ComponentDialog از طریق Activity 1.5.0 به عنوان دیالوگ پیش‌فرض برگردانده شده توسط onCreateDialog() استفاده می‌کند.
  • بازسازی وضعیت نمونه ذخیره شده - فرگمنت‌ها شروع به تغییر نحوه ذخیره وضعیت نمونه خود کرده‌اند. این تلاشی است برای کمک به شناسایی واضح وضعیت ذخیره شده در فرگمنت و منبع آن وضعیت. تغییرات فعلی شامل موارد زیر است:
    • FragmentManager اکنون وضعیت نمونه ذخیره شده خود را به جای ذخیره مستقیم در یک Parcelable سفارشی، در یک Bundle ذخیره می‌کند.
    • نتایجی که از طریق Fragment Result APIs تنظیم شده‌اند و هنوز تحویل داده نشده‌اند، اکنون جدا از وضعیت داخلی FragmentManager ذخیره می‌شوند.
    • وضعیت مرتبط با هر قطعه‌ی مجزا اکنون جداگانه از وضعیت داخلی FragmentManager ذخیره می‌شود، بنابراین به شما امکان می‌دهد میزان وضعیت ذخیره‌شده‌ی مرتبط با یک قطعه‌ی مجزا را با شناسه‌های منحصربه‌فرد موجود در گزارش اشکال‌زدایی Fragment مرتبط کنید.

سایر تغییرات

  • FragmentStrictMode اکنون این امکان را برای قطعات شخص ثالث خصوصی فراهم می‌کند که با استفاده از allowViolation() به همراه نام کلاس، جریمه‌های نقض خاص را دور بزنند.
  • APIهای Fragment برای ارائه منو به ActionBar اکتیویتی شما منسوخ شده‌اند. APIهای MenuHost و MenuProvider که در Activity 1.4.0 اضافه شده‌اند، یک سطح API معادل قابل آزمایش و آگاه از چرخه حیات ارائه می‌دهند که فرگمنت‌ها باید از آن استفاده کنند.

نسخه ۱.۵.۰-rc01

۱۱ مه ۲۰۲۲

androidx.fragment:fragment:1.5.0-rc01 , androidx.fragment:fragment-ktx:1.5.0-rc01 , and androidx.fragment:fragment-testing:1.5.0-rc01 are released. Version 1.5.0-rc01 contains these commits.

Saved Instance State Refactoring

  • The state associated with each individual fragment is now saved separately from the internal state of the FragmentManager , thus allowing you to correlate the amount of saved state associated with an individual fragment with the unique IDs present in the Fragment debug logging . ( a153e0 , b/207158202 )

Version 1.5.0-beta01

۲۰ آوریل ۲۰۲۲

androidx.fragment:fragment:1.5.0-beta01 , androidx.fragment:fragment-ktx:1.5.0-beta01 , and androidx.fragment:fragment-testing:1.5.0-beta01 are released. Version 1.5.0-beta01 contains these commits.

تغییرات API

  • DialogFragment has added a new dismissNow method that uses commitNow for parity with the showNow function. Note that this will not make the Dialog be dismissed immediately, it will only synchronously update the state of the FragmentManager . ( I15c36 , b/72644830 )

Saved Instance State Refactoring

  • FragmentManager now saves its saved instance state into a Bundle instead of directly in a custom Parcelable . This is the first step in providing additional transparency into what is actually being saved by Fragments. ( I93807 , b/207158202 )
  • Results set via the Fragment Result APIs that have not yet been delivered are now saved separately from the internal state of the FragmentManager . This will allow for additional transparency into what results are being saved as part of your saved instance state. ( I6ea12 , b/207158202 )

Version 1.5.0-alpha05

۶ آوریل ۲۰۲۲

androidx.fragment:fragment:1.5.0-alpha05 , androidx.fragment:fragment-ktx:1.5.0-alpha05 , and androidx.fragment:fragment-testing:1.5.0-alpha05 are released. Version 1.5.0-alpha05 contains these commits.

تغییرات API

Version 1.5.0-alpha04

۲۳ مارس ۲۰۲۲

androidx.fragment:fragment:1.5.0-alpha04 , androidx.fragment:fragment-ktx:1.5.0-alpha04 , and androidx.fragment:fragment-testing:1.5.0-alpha04 are released. Version 1.5.0-alpha04 contains these commits.

تغییرات API

  • The Fragment APIs for providing a menu to your activity's ActionBar have been deprecated as they tightly couple your fragment to your activity and are not testable in isolation. The MenuHost and MenuProvider APIs added in Activity 1.4.0-alpha01 provide a testable, lifecycle aware equivalent API surface that fragments should use. ( I50a59 , I20758 )

رفع اشکالات

  • SavedStateViewFactory now supports using CreationExtras even when it was initialized with a SavedStateRegistryOwner . If extras are provided, the initialized arguments are ignored. ( I6c43b , b/224844583 )

Version 1.5.0-alpha03

۲۳ فوریه ۲۰۲۲

androidx.fragment:fragment:1.5.0-alpha03 , androidx.fragment:fragment-ktx:1.5.0-alpha03 , and androidx.fragment:fragment-testing:1.5.0-alpha03 are released. Version 1.5.0-alpha03 contains these commits.

تغییرات API

  • You can now pass CreationExtras to the by viewModels() and by activityViewModels() functions. ( Ibefe7 , b/217601110 )

تغییرات رفتاری

Version 1.5.0-alpha02

February 9, 2022

androidx.fragment:fragment:1.5.0-alpha02 , androidx.fragment:fragment-ktx:1.5.0-alpha02 , and androidx.fragment:fragment-testing:1.5.0-alpha02 are released. Version 1.5.0-alpha02 contains these commits.

ویژگی‌های جدید

  • FragmentStrictMode now offers the ability for private third-party fragments to bypass specific violation penalties by using allowViolation() with the class name. ( I8f678 )

Version 1.5.0-alpha01

January 26, 2022

androidx.fragment:fragment:1.5.0-alpha01 , androidx.fragment:fragment-ktx:1.5.0-alpha01 , and androidx.fragment:fragment-testing:1.5.0-alpha01 are released. Version 1.5.0-alpha01 contains these commits.

ویژگی‌های جدید

رفع اشکالات

  • From Fragment 1.4.1 : FragmentContainerView no longer throws an illegal state exception when view IDs generated from xml have negative values. ( Ic185b , b/213086140 )
  • From Fragment 1.4.1 : When using a custom ownerProducer lambda with the by viewModels() lazy function, it will now use the defaultViewModelProviderFactory from that owner if a custom ViewModelProvider.Factory is not provided instead of always using the fragment's factory. ( I56170 , b/214106513 )
  • Fixed a crash when accessing a ViewModel for the very first time from a registerForActivityResult() callback of a Fragment . ( Iea2b3 )

نسخه ۱.۴

Version 1.4.1

January 26, 2022

androidx.fragment:fragment:1.4.1 , androidx.fragment:fragment-ktx:1.4.1 , and androidx.fragment:fragment-testing:1.4.1 are released. Version 1.4.1 contains these commits.

رفع اشکالات

  • FragmentContainerView no longer throws an illegal state exception when view IDs generated from xml have negative values. ( Ic185b , b/213086140 )
  • When using a custom ownerProducer lambda with the by viewModels() lazy function, it will now use the defaultViewModelProviderFactory from that owner if a custom ViewModelProvider.Factory is not provided instead of always using the fragment's factory. ( I56170 , b/214106513 )

Version 1.4.0

۱۷ نوامبر ۲۰۲۱

androidx.fragment:fragment:1.4.0 , androidx.fragment:fragment-ktx:1.4.0 , and androidx.fragment:fragment-testing:1.4.0 are released. Version 1.4.0 contains these commits.

Important changes since 1.3.0

  • The FragmentStrictMode APIs provide runtime checks that allow you to verify that your app or libraries you depend on are not calling deprecated fragment APIs. When a violation is detected, you can choose to print a log message, trigger your own custom listener, or crash your app. The FragmentStrictMode.Policy that controls what checks are enabled and what “penalties” are triggered can be set on a FragmentManager via the new setStrictModePolicy() method. That policy applies to that FragmentManager and transitively to any child fragment managers that do not set their own unique policy. See StrictMode for fragments .
  • FragmentContainerView now provides a getFragment() method which returns the fragment that was most recently added to the container. This uses the same logic as findFragmentById() with the ID of the FragmentContainerView , but allows chaining the call.

    val navController = binding.container.getFragment<NavHostFragment>().navController
    
  • FragmentScenario now implements Closeable , allowing you to use it with Kotlin's use method or try-with-resources .

  • Added FragmentTransaction#TRANSIT_FRAGMENT_MATCH_ACTIVITY_{OPEN, CLOSE} to specify whether to enable the standard Activity-transition animation taken from your theme in Fragments transition.

  • The experimental API of FragmentManager.enableNewStateManager(boolean) has been removed and the new state manager is now the only option available.

Multiple back stacks

The FragmentManager maintains a back stack made up of fragment transactions that used addToBackStack() . This allows you to pop those transactions and return to the previous state, using the mechanisms for Saving state with fragments to allow your fragments to restore their state appropriately.

This release expands on these mechanisms by providing three new FragmentManager APIs: saveBackStack(String name) , restoreBackStack(String name) , and clearBackStack(String name) . These APIs use the same name as addToBackStack() to save the state of the FragmentTransaction and the state of every fragment that was added in those transactions and allow you to later restore those transactions and their fragments with their state in tact. This allows you to effectively 'swap' between multiple back stacks by saving the current back stack and restoring a saved back stack.

saveBackStack() operates similarly to popBackStack() in that it is asynchronous and results in all the fragment transactions back to that specific name to be reversed ('popped') and any added fragments to be destroyed and removed, but it differs in a few important ways:

  • saveBackStack() is always inclusive.
  • Unlike popBackStack() which will pop all transactions on the back stack if the specified name is not found on the back stack or if a null name is provided, saveBackStack() does nothing if you haven't previously committed a fragment transaction using addToBackStack() with that exact, non-null name.
  • The state of all fragments added from those transactions is saved. This means that the View state of every fragment is stored, onSaveInstanceState() of every fragment is called and that state is restored, and any ViewModel instances associated with those fragments are retained (and onCleared() is not called on them).

The fragment transactions that can be used with saveBackStack() must meet certain criteria:

  • Every fragment transaction must use setReorderingAllowed(true) to ensure the transactions can be restored as a single, atomic operation.
  • The set of transactions saved must be self-contained (ie, they must not explicitly reference any fragments outside of that set of transactions) to ensure that they can be restored at any later time, no matter what changes have been made to the back stack in the intervening time.
  • No fragment that is saved can be a retained fragment or have a retained fragment in their transitive set of child fragments to ensure that the FragmentManager does not return any references to saved fragments after the back stack is saved.

Similar to saveBackStack() , restoreBackStack() and clearBackStack() , which would restore a previously saved back stack or clear a previously saved back stack, respectively, both do nothing if you have not previously called saveBackStack() with the same name.

For more information, see Multiple back stacks: A deep dive .

Version 1.4.0-rc01

November 3, 2021

androidx.fragment:fragment:1.4.0-rc01 released with no changes from Fragment 1.4.0-beta01. Version 1.4.0-rc01 contains these commits.

Version 1.4.0-beta01

۲۷ اکتبر ۲۰۲۱

androidx.fragment:fragment:1.4.0-beta01 , androidx.fragment:fragment-ktx:1.4.0-beta01 , and androidx.fragment:fragment-testing:1.4.0-beta01 are released. Version 1.4.0-beta01 contains these commits.

رفع اشکالات

  • Parent fragments will now dispatch onHiddenChanged() down their entire hierarchy before launching their own callback. ( Iedc20 , b/77504618 )
  • The keyboard will now close automatically when going from a fragment with an open keyboard to a fragment with a recycler view. ( I8b842 , b/196852211 )
  • DialogFragment now uses setReorderingAllowed(true) for all transactions it creates when you call show() , showNow() , or dismiss() . ( Ie2c14 )
  • The extremely long Lint warning of DetachAndAttachFragmentInSameFragmentTransaction has been shortened to DetachAndAttachSameFragment . ( e9eca3 )

Version 1.4.0-alpha10

September 29, 2021

androidx.fragment:fragment:1.4.0-alpha10 , androidx.fragment:fragment-ktx:1.4.0-alpha10 , and androidx.fragment:fragment-testing:1.4.0-alpha10 are released. Version 1.4.0-alpha10 contains these commits.

Lint

  • Added the DetachAndAttachFragmentInSameFragmentTransaction lint warning for detecting calling both detach() and attach() on the same Fragment in the same FragmentTransaction - as these complementary operations cancel each other out when done in the same transaction, they must be split into separate transactions to actually do anything. ( aosp/1832956 , b/200867930 )
  • Added the FragmentAddMenuProvider lint error for correcting usages of the Fragment Lifecycle to the Fragment view Lifecycle when using the addMenuProvider API of MenuHost . ( aosp/1830457 , b/200326272 )

Documentation Updates

  • The deprecation message for APIs now handled by the Activity Result APIs , namely startActivityForResult , startIntentSenderForResult , onActivityResult , requestPermissions , and onRequestPermissionsResult , have all been expanded with more details. ( cce80f )
  • The deprecation message for onActivityCreated() for both Fragment and DialogFragment has all been expanded with more details. ( 224db4 )

Version 1.4.0-alpha09

۱۵ سپتامبر ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha09 , androidx.fragment:fragment-ktx:1.4.0-alpha09 , and androidx.fragment:fragment-testing:1.4.0-alpha09 are released. Version 1.4.0-alpha09 contains these commits.

ویژگی‌های جدید

  • You can now call clearBackStack(name) to clear any state previously saved with saveBackStack(name) . ( I70cd7 )

تغییرات API

  • The FragmentContainerView class has been rewritten in Kotlin ensuring that the getFragment function will properly respect nullability. ( If694a , b/189629145 )
  • FragmentStrictMode is now written in Kotlin ( I11767 , b/199183506 )

رفع اشکالات

  • Fixed an issue where the state of a Fragment that was added with setReorderingAllowed(true) and then immediately removed before executing pending transactions would not be properly cleaned up. ( I8ccb8 )

Version 1.4.0-alpha08

۱ سپتامبر ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha08 , androidx.fragment:fragment-ktx:1.4.0-alpha08 , and androidx.fragment:fragment-testing:1.4.0-alpha08 are released. Version 1.4.0-alpha08 contains these commits.

رفع اشکالات

  • Improved the UseRequireInsteadOfGet Lint check to better handle redundant parenthesis. ( I2d865 )
  • Improved the UseGetLayoutInflater Lint check to handle additional edge cases. ( Ie5423 )

Version 1.4.0-alpha07

۱۸ آگوست ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha07 , androidx.fragment:fragment-ktx:1.4.0-alpha07 , and androidx.fragment:fragment-testing:1.4.0-alpha07 are released with no notable changes. Version 1.4.0-alpha07 contains these commits.

Version 1.4.0-alpha06

۴ آگوست ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha06 , androidx.fragment:fragment-ktx:1.4.0-alpha06 , and androidx.fragment:fragment-testing:1.4.0-alpha06 are released. Version 1.4.0-alpha06 contains these commits.

رفع اشکالات

  • Fixed an issue with multiple back stacks when rapidly swapping between back stacks that would appear as an IllegalStateException while restoring a FragmentTransaction or as a second copy of a fragment appearing. ( I9039f )
  • Fixed an issue where FragmentManager would hold onto a copy of state previously saved via saveBackStack() even after that state was restored. ( Ied212 )
  • The dismissAllowingStateLoss() method of DialogFragment no longer crashes when you call it after the state is saved when specifically adding the DialogFragment via the show(FragmentTransaction, String) method. ( I84422 )

Version 1.4.0-alpha05

July 21, 2021

androidx.fragment:fragment:1.4.0-alpha05 , androidx.fragment:fragment-ktx:1.4.0-alpha05 , and androidx.fragment:fragment-testing:1.4.0-alpha05 are released. Version 1.4.0-alpha05 contains these commits.

رفع اشکالات

  • From Fragment 1.3.6 : The Fragment's view is now properly set to GONE when using hide() when the root view has transitionGroup=”true” set. ( aosp/1766655 , b/193603427 )
  • From Fragment 1.3.6 : FragmentActivity now always unlocks the saved state as its first operation in lifecycle callbacks it overrides. ( I6db7a )

Dependency update

Version 1.4.0-alpha04

۳۰ ژوئن ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha04 , androidx.fragment:fragment-ktx:1.4.0-alpha04 , and androidx.fragment:fragment-testing:1.4.0-alpha04 are released. Version 1.4.0-alpha04 contains these commits.

تغییرات API

  • FragmentManager now uses SavedStateRegistry under the hood to save its state. The saveAllState() and restoreSavedState() methods have also been deprecated in FragmentController . If you are using FragmentController to host fragments outside of FragmentActivity , you should have your FragmentHostCallbacks implement SavedStateRegistryOwner . ( Iba68e , b/188734238 )

رفع اشکالات

  • Fixed an issue where the call to saveBackStack() as part of supporting multiple back stacks would fail when done at the same time as running a FragmentTransaction that used replace() . ( I73137 )
  • Fixed a NullPointerException that would occur after manually restoring a saved back stack that contained multiple transactions when using the restoreBackStack() API for multiple back stack support. This also fixed an issue where setReorderingAllowed(true) was not being checked for all transactions. ( I8c593 )
  • Fixed an issue where FragmentManager would incorrectly continue to restore previously saved state of fragments even after those fragments were removed from the FragmentManager , thus causing the saved state to continuously grow over time. ( I1fb8e )

Version 1.4.0-alpha03

۱۶ ژوئن ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha03 , androidx.fragment:fragment-ktx:1.4.0-alpha03 , and androidx.fragment:fragment-testing:1.4.0-alpha03 are released. Version 1.4.0-alpha03 contains these commits.

ویژگی‌های جدید

  • All Fragment StrictMode Violation classes have been updated with more detailed error messages that explain the details of the violation. ( b/187871638 )
    • FragmentTagUsageViolation now contains more detailed error message that container the parent container that the fragment would have been added to. ( Ic33a7 )
    • WrongFragmentContainerViolation now has more detailed error message that includes the container that the fragment was being added to. ( Ib55f8 )
    • The use case classes for TargetFragmentUsageViolation now have more detailed error messages to include the fragment causing the violation and any other contained information. ( Icc6ac )
    • The classes extending RetainInstanceUsageViolation now have more detailed error messages that include the fragment causing the violation. ( I6bd55 )
    • FragmentReuseViolation now has more detailed error message that includes the previous id of the fragment. ( I28ce2 )
    • SetUserVisibleHintViolation now has more detailed error message that includes what the user visible hint was being set to. ( Ib2d5f )

تغییرات رفتاری

  • Reverted the restriction on calling fitsSystemWindows on a FragmentContainerView - this no longer crashes your app. ( 6b8ddd , b/190622202 )

رفع اشکالات

  • From Fragment 1.3.5 : Fixed a regression in shared element transitions introduced in Fragment 1.3.4 by aosp/1679887 . Fragments now correctly handle transition groups (either set directly via transitionGroup="true" or indirectly via a transitionName or background ) and shared elements will no longer throw IndexOutOfBoundsException s. ( I16484 , b/188679569 , b/188969304 )
  • The FragmentManager will no longer crash when you attempt to hide a removing fragment. ( I573dd , b/183634730 )
  • The OnCreateDialogIncorrectCallback lint check will no longer crash when evaluating a top level variable. ( 0a9efa , b/189967522 )

Version 1.4.0-alpha02

۲ ژوئن ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha02 , androidx.fragment:fragment-ktx:1.4.0-alpha02 , and androidx.fragment:fragment-testing:1.4.0-alpha02 are released. Version 1.4.0-alpha02 contains these commits.

ویژگی‌های جدید

  • FragmentStrictMode will now always log violations when logging is enabled via the FragmentManager , regardless of the current strict mode policy being used. ( I02df6 , b/187872638 )
  • FragmentStrictMode now supports exempting particular Fragment classes from strict mode Violation s allowing that class to bypass any penalties. ( Ib4e5d , b/184786736 )

  • The FragmentStrictMode Violation class has been expanded to add structure information based on each violation. This allows you to verify exactly what caused the violation along with the violating fragment ( If5118 , b/187871150 ), each Violation contains the following:

    • WrongFragmentContainerViolation now contains the ViewGroup that the Fragment was attempting to be added to. ( I83c75 , b/187871150 )
    • TargetFragmentUsageViolation has been expanded into, SetTargetFragmentUsageViolation , GetTargetFragmentUsageViolation , and GetTargetFragmentRequestCodeUsageViolation , with SetTargetFragmentUsageViolation containing the target fragment and request code. ( I741b4 , b/187871150 )
    • SetUserVisibleHintViolation now contains the boolean value passed into setUserVisibleHint() . ( I00585 , b/187871150 )
    • FragmentTagUsageViolation now contains the ViewGroup that the <fragment> tag was attempting to inflate a fragment into.( I5dbbc , b/187871150 )
    • FragmentReuseViolation now contains the unique ID of the previous instance of the Fragment that caused the viotion. ( I0544d , b/187871150 )
    • RetainInstanceUsageViolation is now abstract and has two subclasses, SetRetainInstanceUsageViolation and GetRetainInstanceUsageViolation , representing the two cases for the violation type. ( Ic81e5 , b/187871150 )

تغییرات رفتاری

  • FragmentContainerView now throws an exception when attempting to change the fitsSystemWindow attribute programmatically or via XML. Insets should be handled by each individual fragment's view. ( Ie6651 , b/187304502 )

Version 1.4.0-alpha01

۱۸ مه ۲۰۲۱

androidx.fragment:fragment:1.4.0-alpha01 , androidx.fragment:fragment-ktx:1.4.0-alpha01 , and androidx.fragment:fragment-testing:1.4.0-alpha01 are released. Version 1.4.0-alpha01 contains these commits.

ویژگی‌های جدید

  • FragmentContainerView now provides a getFragment() method which returns the fragment that was most recently added to the container. This uses the same logic as findFragmentById() with the ID of the FragmentContainerView , but allows chaining the call. ( Ife17a , b/162527857 )

    val navController = binding.container.getFragment<NavHostFragment>().navController
    
  • Added FragmentTransaction#TRANSIT_FRAGMENT_MATCH_ACTIVITY_{OPEN, CLOSE} to specify whether to enable the standard Activity-transition animation taken from your theme in Fragments transition. ( I46652 )

Multiple back stacks

The FragmentManager maintains a back stack made up of fragment transactions that used addToBackStack() . This allows you to pop those transactions and return to the previous state, using the mechanisms for Saving state with fragments to allow your fragments to restore their state appropriately.

This release expands on these mechanisms by providing two new FragmentManager APIs: saveBackStack(String name) and restoreBackStack(String name) . These APIs use the same name as addToBackStack() to save the state of the FragmentTransaction and the state of every fragment that was added in those transactions and allow you to later restore those transactions and their fragments with their state in tact. This allows you to effectively 'swap' between multiple back stacks by saving the current back stack and restoring a saved back stack.

saveBackStack() operates similarly to popBackStack() in that it is asynchronous and results in all the fragment transactions back to that specific name to be reversed ('popped') and any added fragments to be destroyed and removed, but it differs in a few important ways:

  • saveBackStack() is always inclusive.
  • Unlike popBackStack() which will pop all transactions on the back stack if the specified name is not found on the back stack or if a null name is provided, saveBackStack() does nothing if you haven't previously committed a fragment transaction using addToBackStack() with that exact, non-null name.
  • The state of all fragments added from those transactions is saved. This means that the View state of every fragment is stored, onSaveInstanceState() of every fragment is called and that state is restored, and any ViewModel instances associated with those fragments are retained (and onCleared() is not called on them).

The fragment transactions that can be used with saveBackStack() must meet certain criteria:

  • Every fragment transaction must use setReorderingAllowed(true) to ensure the transactions can be restored as a single, atomic operation.
  • The set of transactions saved must be self-contained (ie, they must not explicitly reference any fragments outside of that set of transactions) to ensure that they can be restored at any later time, no matter what changes have been made to the back stack in the intervening time.
  • No fragment that is saved can be a retained fragment or have a retained fragment in their transitive set of child fragments to ensure that the FragmentManager does not return any references to saved fragments after the back stack is saved.

Similar to saveBackStack() , restoreBackStack() does nothing if you have not previously called saveBackStack() with the same name. ( b/80029773 )

Fragment StrictMode

The FragmentStrictMode APIs provide runtime checks that allow you to verify that your app or libraries you depend on are not calling deprecated fragment APIs. When a violation is detected, you can choose to print a log message, trigger your own custom listener, or crash your app. The FragmentStrictMode.Policy that controls what checks are enabled and what “penalties” are triggered can be set on a FragmentManager via the new setStrictModePolicy() method. That policy applies to that FragmentManager and transitively to any child fragment managers that do not set their own unique policy. ( #123 , #131 , #150 , b/143774122 )

  • detectFragmentReuse() detects whether a previously removed Fragment instance is being re-added to a FragmentManager . You should never interact with or keep a reference to a Fragment instance after it has been destroyed and removed from a FragmentManager . ( #142 , b/153738653 )
  • detectFragmentTagUsage() detects when you are using the <fragment> tag in your layout XML. You should always use FragmentContainerView when inflating fragments as part of your layout. ( #141 , b/153738235 )
  • detectWrongFragmentContainer() detects when you add a fragment to a container that is not a FragmentContainerView . You should always use FragmentContainerView as the container for fragments in your layout. ( #146 , b/181137036 )
  • detectRetainInstanceUsage() detects when you use the deprecated setRetainInstance() or getRetainInstance() APIs. ( #140 , b/153737954 )
  • detectSetUserVisibleHint() detects when you use the deprecated setUserVisibleHint() API. ( #136 , b/153738974 )
  • detectTargetFragmentUsage() detects when you use the deprecated setTargetFragment() , getTargetFragment() or getTargetRequestCode() APIs. ( #139 , b/153737745 )

تغییرات API

New Lint checks

  • The UseGetLayoutInflater Lint check now warns when using LayoutInflater.from(Context) within a DialogFragment - you should always use the dialog fragment's getLayoutInflater() method to get the appropriate for LayoutInflater . ( #156 , b/170781346 )
  • The DialogFragmentCallbacksDetector Lint check now warns when calling setOnCancelListener or setOnDismissListener in the onCreateDialog() method of a DialogFragment - these listeners are owned by the DialogFragment itself and you should override onCancel() and onDismiss() to receive these callbacks. ( #171 , b/181780047 , b/187524311 )

رفع اشکالات

  • From Fragment 1.3.4 : Fixed a regression introduced in Fragment 1.3.3 when using the ViewTreeViewModelStoreOwner.get() API with ViewModelProvider or the Jetpack Compose method of viewModel() inside a Fragment. These use cases now correctly use the ViewModelProvider.Factory provided by your Fragment if it overrides getDefaultViewModelProviderFactory() (as @AndroidEntryPoint annotated Fragments do when using Hilt). If you do not override that method, a SavedStateViewModelFactory that saves and restores its state alongside the Fragment's view is created as the default factory. ( I5cbfa , b/186097368 )
  • From Fragment 1.3.4 : When using FragmentContainerView on API 29, insets will no longer dispatch indefinitely, fixing issues with BottomNavigationBar and FloatingActionButton instances. ( I1bb78 , b/186012452 )
  • From Fragment 1.3.4 : You can now retrieve your Parcelable from the fragment result bundle after process death. ( I65932 , b/187443158 )
  • From Fragment 1.3.4 : When doing a shared element transition on a ViewGroup, if the ViewGroup has transitionGroup set to false, it will now properly transition. ( I99675 )

مشارکت خارجی

Version 1.3

Version 1.3.6

July 21, 2021

androidx.fragment:fragment:1.3.6 , androidx.fragment:fragment-ktx:1.3.6 , and androidx.fragment:fragment-testing:1.3.6 are released. Version 1.3.6 contains these commits.

رفع اشکالات

  • From Fragment 1.4.0-alpha03 : The FragmentManager will no longer crash when you attempt to hide a removing fragment. ( I573dd , b/183634730 )
  • The Fragment's view is now properly set to GONE when using hide() when the root view has transitionGroup=”true” set. ( aosp/1766655 , b/193603427 )
  • FragmentActivity now always unlocks the saved state as its first operation in lifecycle callbacks it overrides. ( I6db7a )

Dependency update

Version 1.3.5

۱۶ ژوئن ۲۰۲۱

androidx.fragment:fragment:1.3.5 , androidx.fragment:fragment-ktx:1.3.5 , and androidx.fragment:fragment-testing:1.3.5 are released. Version 1.3.5 contains these commits.

رفع اشکالات

  • Fixed a regression in shared element transitions introduced in Fragment 1.3.4 by aosp/1679887 . Fragments now correctly handle transition groups (either set directly via transitionGroup="true" or indirectly via a transitionName or background ) and shared elements will no longer throw IndexOutOfBoundsException s. ( I16484 , b/188679569 , b/188969304 )

Version 1.3.4

۱۸ مه ۲۰۲۱

androidx.fragment:fragment:1.3.4 , androidx.fragment:fragment-ktx:1.3.4 , and androidx.fragment:fragment-testing:1.3.4 are released. Version 1.3.4 contains these commits.

رفع اشکالات

  • Fixed a regression introduced in Fragment 1.3.3 when using the ViewTreeViewModelStoreOwner.get() API with ViewModelProvider or the Jetpack Compose method of viewModel() inside a Fragment when using Hilt. These use cases now correctly use the ViewModelProvider.Factory provided by your Fragment if it overrides getDefaultViewModelProviderFactory() (as @AndroidEntryPoint annotated Fragments do). If you do not override that method, a SavedStateViewModelFactory that saves and restores its state alongside the Fragment's view is created as the default factory. ( I5cbfa , b/186097368 )
  • When using FragmentContainerView on API 29, insets will no longer dispatch indefinitely, fixing issues with BottomNavigationBar and FloatingActionButton instances. ( I1bb78 , b/186012452 )
  • You can now retrieve your Parcelable from the fragment result bundle after process death. ( I65932 , b/187443158 )
  • When doing a shared element transition on a ViewGroup, if the ViewGroup has transitionGroup set to false, it will now properly transition. ( I99675 )

Version 1.3.3

۲۱ آوریل ۲۰۲۱

androidx.fragment:fragment:1.3.3 , androidx.fragment:fragment-ktx:1.3.3 , and androidx.fragment:fragment-testing:1.3.3 are released. Version 1.3.3 contains these commits.

ویژگی‌های جدید

  • Using SavedStateViewModelFactory now works when used with the SavedStateRegistryOwner returned by using ViewTreeSavedStateRegistryOwner.get() with the Fragment's View. ( I21acf , b/181577191 )

رفع اشکالات

  • Fixed a regression introduced in Fragment 1.3.2 which would cause popEnter animations to not run when popping a FragmentTransaction that included a setPrimaryNavFragment operation, such as those used by NavHostFragment . ( I38c87 , b/183877426 )
  • FragmentContainerView now ensures that every Fragment is dispatched a new set of WindowInsets , ensuring that each fragment can now independently consume the insets. ( I63f68 , b/172153900 )
  • DialogFragment now properly handles cases where a child fragment is added to a container that has the same ID as a container in your custom Dialog class, fixing view hierarchy issues when reusing IDs that are used internally by dialogs such as BottomSheetDialog . ( Ie6279 , b/180021387 )
  • FragmentManager.dump() now properly indents the first fragment in the list of active fragments. ( If5c33 , b/183705451 )

New State Manager Bug Fixes

  • The new fragment state manager now properly handles exit transitions with hide operations. ( I9e4de , b/184830265 )

Version 1.3.2

۲۴ مارس ۲۰۲۱

androidx.fragment:fragment:1.3.2 , androidx.fragment:fragment-ktx:1.3.2 , and androidx.fragment:fragment-testing:1.3.2 are released. Version 1.3.2 contains these commits.

New State Manager Bug Fixes

  • When running both popBackStack() and commit() operations together, the last operation will now set the direction for all animations rather than running some pop animations and some enter animations. ( I7072e , b/181142246 )
  • Views within in a shared element hierarchy will no longer have their transition name cleared when doing a shared element transition. ( I4d4a6 , b/179934757 )

به‌روزرسانی‌های وابستگی

  • Fragment now depends on Activity 1.2.2 , fixing an issue with Activity's InvalidFragmentVersionForActivityResult lint check when using Fragment 1.3.1 or higher.
  • Fragment now depends on Lifecycle 2.3.1 .

Version 1.3.1

March 10, 2021

androidx.fragment:fragment:1.3.1 , androidx.fragment:fragment-ktx:1.3.1 , and androidx.fragment:fragment-testing:1.3.1 are released. Version 1.3.1 contains these commits.

ویژگی‌های جدید

  • Dialogs within a DialogFragment can now get access to ViewTree owners through their DecorView, ensuring that DialogFragment can be used with ComposeView . ( Ib9290 , b/180691023 )

رفع اشکالات

  • Fragments inflated into an already RESUMED activity using FragmentContainerView are now properly shown after a configuration change. ( Ie14c8 , b/180538371 )
  • There is no longer an extra } at the end of the fragment toString() ( I54705 , b/177761088 )
  • Overridden methods in FragmentActivity now properly inherit the base method javaDoc ( I736ce , b/139548782 )
  • The docs for setFragmentResult and setFragmentResultListener have updated their parameters docs to reflect that they no longer accept nullables ( I990ba , b/178348386 )

New State Manager Bug Fixes

  • Fixed a memory leak in fragments caused by mFocusedView ( Ib4e9e , b/179925887 )
  • Fragments now properly call onCreateOptionsMenu when using show/hide transactions ( I8bce8 , b/180255554 )
  • Child fragments with transitions that start prior to the fragment being laid out will now properly reach RESUMED ( Ic11e6 , b/180825150 )
  • Fragments inflated using the <fragment> tag will now always make it to RESUMED ( I452ac , ( I9fa49 )

به‌روزرسانی‌های وابستگی

Version 1.3.0

۱۰ فوریه ۲۰۲۱

androidx.fragment:fragment:1.3.0 , androidx.fragment:fragment-ktx:1.3.0 , and androidx.fragment:fragment-testing:1.3.0 are released. Version 1.3.0 contains these commits.

Major changes since 1.2.0

  • New State Manager : A significant rewrite of the internals of FragmentManager has fixed numerous issues around the dispatch of lifecycle events, animations and transitions, and how postponed fragments are handled.
  • Activity Result API Integration : Added support for the ActivityResultRegistry API introduced in Activity 1.2.0 to handle startActivityForResult() + onActivityResult() as well as requestPermissions() + onRequestPermissionsResult() flows without overriding methods in your Fragment in addition to providing hooks for testing these flows. See the updated Getting a Result from an Activity .

    • This release fixes a number of issues around invalid request codes and the dispatch of permission requests that prevent the Activity Result API from working on previous versions of FragmentActivity . You must upgrade to Fragment 1.3.0 to use the Activity Result APIs in a FragmentActivity or AppCompatActivity .
  • Fragment Result API : Added support for passing results between two Fragments via new APIs on FragmentManager . This works for hierarchy fragments (parent/child), DialogFragments, and fragments in Navigation and ensures that results are only sent to your Fragment while it is at least STARTED . The target fragment APIs have been deprecated in favor of these new APIs. See Get Results using the Fragment Result API .

  • FragmentOnAttachListener : The onAttachFragment() callback on FragmentActivity and Fragment have been deprecated. A new FragmentOnAttachListener has been added to provide a more flexible alternative, allowing delegation of onAttachFragment() to separate, testable listeners and support for adding a listener to FragmentManagers other than your direct child FragmentManager.

  • FragmentScenario Improvements : The FragmentScenario class from the fragment-testing artifact has been rewritten in Kotlin and has received a number of improvements:

    • FragmentScenario now uses setMaxLifecycle() to implement moveToState() , ensuring consistent behavior on all API levels and decoupling the Fragment's state from the underlying Activity.
    • FragmentScenario now supports setting an initial Lifecycle.State to support asserting the fragment's state before moving to each Lifecycle.State for the first time.
    • There is now an alternative to the FragmentScenario API of onFragment in the form of the Kotlin reified extension method withFragment that allows you to return a value. Notably, it rethrows exceptions raised in the given block.
  • ViewTree Support : Fragment now supports the ViewTreeLifecycleOwner.get(View) , ViewTreeViewModelStoreOwner.get(View) , and ViewTreeSavedStateRegistryOwner APIs added in Lifecycle 2.3.0 and SavedState 1.1.0 such that it will return the Fragment as the ViewModelStoreOwner , and a SavedStateRegistryOwner and LifecycleOwner tied to the fragment's view Lifecycle when using a View within a Fragment .

  • TRANSIT_ animation changes : The fragment default effects, TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , and TRANSIT_FRAGMENT_FADE , now use Animator instead of Animation . The resources used to build these animators are now private.

  • setRetainInstance() deprecation : The setRetainInstance() method on Fragments has been deprecated. With the introduction of ViewModels , developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate, avoiding a common source of leaks while maintaining the useful properties of a single creation and destruction of the retained state (namely, the constructor of the ViewModel and the onCleared() callback it receives).

  • ViewPager 1 adapter deprecation : With the release of ViewPager2 1.0.0 , the FragmentPagerAdapter and FragmentStatePagerAdapter classes for interacting with ViewPager have been deprecated. See Migrate from ViewPager to ViewPager2 .

Version 1.3.0-rc02

۲۷ ژانویه ۲۰۲۱

androidx.fragment:fragment:1.3.0-rc02 , androidx.fragment:fragment-ktx:1.3.0-rc02 , and androidx.fragment:fragment-testing:1.3.0-rc02 are released. Version 1.3.0-rc02 contains these commits.

رفع اشکالات

  • Fixed an issue where a parent DialogFragment would appear above a child DialogFragment after a configuration change; child dialog fragments now always appear above a parent dialog fragment. ( I30806 , b/177439520 )
  • Fixed issue where doing a hide operation with an Animation would cause the hiding fragment to flash at the end of the animation. ( I57e22 , b/175417675 )
  • Fragments with transitions added before the view hierarchy is attached now properly reach RESUMED . ( I1fc1d , b/177154873 )

New State Manager Bug Fixes

  • The Fragment's view Lifecycle now properly handles cases where the Fragment's view is destroyed before the Lifecycle reaches CREATED , avoiding exceptions stating “no event down from INITIALIZED”. ( eda2bd , b/176138645 )
  • Fragments that use an Animator now appear in the proper order when using FragmentContainerView . ( Id9aa3 , b/176089197 )

Version 1.3.0-rc01

۱۶ دسامبر ۲۰۲۰

androidx.fragment:fragment:1.3.0-rc01 , androidx.fragment:fragment-ktx:1.3.0-rc01 , and androidx.fragment:fragment-testing:1.3.0-rc01 are released. Version 1.3.0-rc01 contains these commits.

رفع اشکالات

  • onPrepareOptionsMenu() now follows the same logic as onCreateOptionsMenu() and is no longer called when a parent fragment calls setMenuVisibility(false) . ( Id7de8 , b/173203654 )

New State Manager Bug Fixes

  • Fixed leak and visual artifact when adding a fragment with an Animation to a FragmentContainerView and then interrupting that addition with a pop operation. ( I952d8 )
  • Fixed an issue where the fragment's view would remain in the view hierarchy if it was replaced during its onCreate() or onViewCreated() methods. ( I8a7d5 )
  • Focus is now properly restored to Fragment root views when they are resumed. ( Ifc84b )
  • Combining pop and replace operations in the same fragment transaction will now show the proper animations ( Ifd4e4 , b/170328691 )

Version 1.3.0-beta02

۲ دسامبر ۲۰۲۰

androidx.fragment:fragment:1.3.0-beta02 , androidx.fragment:fragment-ktx:1.3.0-beta02 , and androidx.fragment:fragment-testing:1.3.0-beta02 are released. Version 1.3.0-beta02 contains these commits.

ویژگی‌های جدید

  • FragmentScenario has been fully converted to Kotlin while maintaining source and binary compatibility via usage of Kotlin 1.4's functional interfaces for FragmentAction . ( I19d31 )

تغییرات رفتاری

  • FragmentContainerViews that do not inflate a fragment using the class or android:name attribute can now be used outside of a FragmentActivity . ( Id4397 , b/172266337 )
  • Attempting to set the max lifecycle of a fragment to DESTROYED will now throw an IllegalArgumentException ( Ie7651 , b/170765622 )
  • Initializing a FragmentScenario with a DESTROYED state will now throw an IllegalArgumentException ( I73590 , b/170765622 )

New State Manager Bug Fixes

  • Fixed an issue where the view would not reach its final state if you interrupt a fragment transition that was using an Animator or one of the TRANSIT_FRAGMENT_ options. ( I92426 , b/169874632 )
  • Fixed an issue that prevented fragments with an exiting Animation from being properly destroyed. ( I83d65 )
  • Exiting fragments that have their effects reversed now correctly cancel and restart with the proper entering effect. ( I62226 , b/167092035 )
  • Fixed an issue where the exit Animator of a hide() would not run. ( Id7ffe )
  • Fragments now properly appear when postponed and then immediately started. ( Ie713b , b/170022857 )
  • Fragments that remove their focused view during an animation will no longer attempt to restore the focus on the detached view once they reach RESUMED ( I38c65 , b/172925703 )

مشارکت خارجی

  • FragmentFactory now caches fragment classes separately for different ClassLoader instances. Thanks Simon Schiller! ( #87 , b/113886460 )

Version 1.3.0-beta01

۱ اکتبر ۲۰۲۰

androidx.fragment:fragment:1.3.0-beta01 , androidx.fragment:fragment-ktx:1.3.0-beta01 , and androidx.fragment:fragment-testing:1.3.0-beta01 are released. Version 1.3.0-beta01 contains these commits.

ویژگی‌های جدید

  • setMaxLifecycle() now supports setting the Lifecycle state to INITIALIZING as long as the fragment has not been moved to CREATED . ( b/159662173 )

تغییرات API

تغییرات رفتاری

  • Fragment resource files have been correctly made private. ( aosp/1425237 )

رفع اشکالات

  • Fragments inflated using the <fragment> tag will now properly wait until their views are added to a container before moving to STARTED ( I02f4c )
  • Fragments that are visible and then setMaxLifecycle() to CREATED now properly run their exit effects. ( b/165822335 )
  • Removing a detached fragment that is not added to the back stack no longer causes a memory leak. Courtesy of Nicklas Ansman Giertz! ( b/166489383 )
  • Active fragments will now always have a non-null FragmentManager and fragments with a non-null FragmentManager will always be considered active. ( aosp/1422346 )
  • The fragment default effects, TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , and TRANSIT_FRAGMENT_FADE , now use Animator instead of Animation . ( b/166155034 )

New State Manager Bug Fixes

  • Fragments now properly restore their view focus state from right before they start their animation. ( Icc256 )
  • Fragments that only have a shared element transition now properly complete their special effects meaning they actually move to their final state ( Iaebc7 , b/166658128 )
  • Fragment views are now always removed from the container before being destroyed. ( Id5876 )
  • The new state manager now consistently removes the exiting fragment view before adding the entering one. ( I41a6e )
  • Explicit changes to a fragment view's visibility are now respected by the new state manager. This means that if you set an entering fragment's view to INVISIBLE before the animation begins, it will actually stay invisible. ( b/164481490 )
  • Fragments now prioritize Animators over Animations , meaning a fragment with both will only run the Animator and ignore the Animation . ( b/167579557 )
  • The new state manager no longer causes fragments to flash when using entering animations. ( b/163084315 )

Known Issue

When using the new state manager, if you press back during an entering special effect instead of returning to the previous fragment, the old fragment is never re-added, resulting in a blank screen. ( b/167259187 , b/167092035 , b/168442830 )

Version 1.3.0-alpha08

۱۹ آگوست ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha08 , androidx.fragment:fragment-ktx:1.3.0-alpha08 , and androidx.fragment:fragment-testing:1.3.0-alpha08 are released. Version 1.3.0-alpha08 contains these commits.

New State Manager

This release includes a major refactoring of the internal state management of FragmentManager which affects the dispatch of lifecycle methods, animations and transitions, and how postponed transactions are handled. This is enabled by default. See the Fragments: Rebuilding the Internals blog post for more details. ( b/139536619 , b/147749580 )

  • An experimental API in FragmentManager.enableNewStateManager(boolean) can be used to control whether FragmentManager uses the new state manager. ( I7b6ee )

The following issues are fixed only when using the new state manager:

  • The previous fragment of a replace operation is now correctly stopped before the new fragment is started. ( b/161654580 )
  • Fragments now prevent multiple competing animations on the same fragments, avoiding cases where an Animation would override all Transition effects or an Animator and a Transition on an individual fragment would both run. ( b/149569323 )
  • The enterTransition and exitTranstion of all fragments entering and exiting are now ran rather than only the last entering fragment and the first exiting fragment. ( b/149344150 )
  • Postponed fragments no longer get stuck at the CREATED state but instead move to STARTED with other fragments. ( b/129035555 )
  • Fixed an issue where FragmentManager would execute operations out of order when mixing a postponed re-ordered transaction and a non-reordered transaction. ( b/147297731 )
  • Popping multiple fragments simultaneously will no longer result in intermediate fragments being temporarily visible when postponing fragments. ( b/37140383 )
  • FragmentManager now returns the correct fragments when calling findFragmentById() or findFragmentByTag() from within the onAttachFragment() callback. ( b/153082833 )
  • Fragments no longer call onCreateView() on fragments being destroyed when the fragment replacing them is postponed. ( b/143915710 )
  • The error message when attempting to combine framework Transition and AndroidX Transition instances now mentions the fragment with the invalid transition. ( b/155574969 )

تغییرات رفتاری

  • You can now call launch() on an ActivityResultLauncher in the onCreate() lifecycle method of a fragment. ( b/161464278 )
  • Calling registerForActivityResult() after onCreate() now throws an exception indicating that this is not allowed rather than silently failing to deliver results after a configuration change. ( b/162255449 )
  • FragmentActivity now uses the OnContextAvailableListener API introduced in Activity 1.2.0-alpha08 to restore the state of the FragmentManager . Any listeners added to subclasses of FragmentActivity will run after this listener. ( I513da )

رفع اشکالات

  • ActivityOptions passed through when using startIntentSenderForResult() are now respected. ( b/162247961 )

Known Issue

  • When using the new state manager, directly setting the visibility of the fragment's root view after onViewCreated() and before onResume() results in the visibility you set being overridden by FragmentManager , who controls the visibility of the root view. As a workaround, you should always use the hide() and show() operations to change the visibility of your fragment. ( b/164481490 )

Version 1.3.0-alpha07

۲۲ ژوئیه ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha07 , androidx.fragment:fragment-ktx:1.3.0-alpha07 , and androidx.fragment:fragment-testing:1.3.0-alpha07 are released. Version 1.3.0-alpha07 contains these commits.

ویژگی‌های جدید

  • FragmentScenario now supports setting an initial Lifecycle state of CREATED , STARTED , or RESUMED rather than always moving the Fragment to the RESUMED state. ( b/159662750 )
  • Added an alternative to the FragmentScenario API of onFragment in the form of the Kotlin reified extension method withFragment that allows you to return a value. Notably, it rethrows exceptions raised in the given block. ( b/158697631 )

تغییرات رفتاری

  • FragmentScenario now uses setMaxLifecycle() to implement moveToState() , ensuring consistent behavior on all API levels and decoupling the Fragment's state from the underlying Activity. ( b/156527405 )
  • The SavedStateRegistryOwner returned by ViewTreeSavedStateRegistryOwner is now tied to the fragment view's Lifecycle. This ensures that it has its state saved and restore at the same time as the fragment's view. ( b/158503763 )

رفع اشکالات

  • Fragments now wait for the fragment's view to be attached before calling ViewCompat.requestApplyInsets() , avoiding cases where the inset request was being dropped. ( b/158095749 )
  • Calling clearFragmentResultListener now properly clears the lifecycle observer. ( b/159274993 )

Version 1.3.0-alpha06

۱۰ ژوئن ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha06 , androidx.fragment:fragment-ktx:1.3.0-alpha06 , and androidx.fragment:fragment-testing:1.3.0-alpha06 are released. Version 1.3.0-alpha06 contains these commits.

ویژگی‌های جدید

  • The onAttachFragment() callback on FragmentActivity and Fragment have been deprecated. A new FragmentOnAttachListener has been added to provide a more flexible alternative, allowing delegation of onAttachFragment() to separate, testable listeners and support for adding a listener to FragmentManagers other than your direct child FragmentManager. ( I06d3d )

رفع اشکالات

  • Parent fragments now have their view state restored before their child fragments, fixing a visual ordering issue after a configuration change when a DialogFragment would show another DialogFragment as a child fragment. ( b/157195715 )
  • Fixed an issue where the UseRequireInsteadOfGet Lint check would not handle chained usages of the ?. and !! operators correctly. ( b/157677616 )

Version 1.3.0-alpha05

۲۰ مه ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha05 , androidx.fragment:fragment-ktx:1.3.0-alpha05 , and androidx.fragment:fragment-testing:1.3.0-alpha05 are released. Version 1.3.0-alpha05 contains these commits.

ویژگی‌های جدید

تغییرات API

  • The setFragmentResult() and setFragmentResultListener() APIs now take a non-null Bundle and FragmentResultListener , respectively. To explicitly clear a previously set result or listener, use the new clearFragmentResult() and clearFragmentResultListener() methods. ( b/155416778 )
  • The setFragmentResultListener() Kotlin extensions that take a lambda are now marked as inline . ( b/155323404 )

تغییرات رفتاری

  • The previously deprecated startActivityForResult() , startIntentSenderForResult() , and requestPermissions on Fragment now internally use ActivityResultRegistry , thus removing the restriction on using only the lower bits (below 0xFFFF ) for your request codes when using those APIs. ( b/155518741 )

Documentation Updates

  • Expanded the documentation on the Fragment(@LayoutRes int) and DialogFragment(@LayoutRes int) constructors to clarify that they should be called from your subclasses' no argument constructor when using the default FragmentFactory . ( b/153042497 )

Version 1.3.0-alpha04

۲۹ آوریل ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha04 , androidx.fragment:fragment-ktx:1.3.0-alpha04 , and androidx.fragment:fragment-testing:1.3.0-alpha04 are released. Version 1.3.0-alpha04 contains these commits.

ویژگی‌های جدید

  • Added support for passing results between two Fragments via new APIs on FragmentManager . This works for hierarchy fragments (parent/child), DialogFragments, and fragments in Navigation and ensures that results are only sent to your Fragment while it is at least STARTED . ( b/149787344 )

تغییرات API

  • The target fragment APIs have been deprecated. To pass data between fragments the new Fragment Result APIs should be used instead. ( b/149787344 )
  • The startActivityForResult() / onActivityResult() and requestPermissions() / onRequestPermissionsResult() APIs on Fragment have been deprecated. Please use the Activity Result APIs . ( aosp/1290887 )
  • Breaking change from Activity 1.2.0-alpha04 : the prepareCall() method has been renamed to registerForActivityResult() . ( aosp/1278717 )

رفع اشکالات

  • The fragment's getViewLifecycleOwner() is now stopped before onSaveInstanceState() is called, mirroring the behavior of the fragment's lifecycle. ( b/154645875 )
  • Calling setMenuVisibility(false) on a fragment now correctly changes the visibility of menus provided by its child fragments. ( b/153593580 )
  • Fixed an illegalStateException when adding a fragment to a DialogFragment 's view hierarchy with FragmentContainerView . ( b/154366601 )
  • The getDefaultViewModelProviderFactory() method on fragments no longer crashes when hosting your fragments outside of an activity. ( b/153762914 )

Version 1.3.0-alpha03

April 1, 2020

androidx.fragment:fragment:1.3.0-alpha03 , androidx.fragment:fragment-ktx:1.3.0-alpha03 , and androidx.fragment:fragment-testing:1.3.0-alpha03 are released. Version 1.3.0-alpha03 contains these commits.

تغییرات API

  • The prepareCall methods on Fragment are now final . ( b/152439361 )

رفع اشکالات

  • Fixed a regression introduced in Fragment 1.3.0-alpha02 when using BottomSheetDialogFragment . ( b/151652127 , aosp/1263328 , aosp/1265163 )
  • Fixed a crash when using prepareCall from a fragment after a configuration change. ( b/152137004 )
  • Fixed an issue where shared element and exit transitions are ignored when using setTargetFragment() . ( b/152023196 )
  • From Fragment 1.2.4 : Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. ( b/151605338 )
  • From Fragment 1.2.4 : Disabled the FragmentLiveDataObserve Lint rule on DialogFragment classes as their lifecycle and view lifecycle are always in sync, making it safe to use either this or viewLifecycleOwner when calling observe . ( b/151765086 )

Dependency Changes

  • Fragments depend on Activity 1.2.0-alpha03 , which had significant improvements to the Activity Result API introduced in Activity 1.2.0-alpha02 .

Version 1.3.0-alpha02

۱۸ مارس ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha02 , androidx.fragment:fragment-ktx:1.3.0-alpha02 , and androidx.fragment:fragment-testing:1.3.0-alpha02 are released. Version 1.3.0-alpha02 contains these commits.

ویژگی‌های جدید

  • Added support for the ActivityResultRegistry API introduced in Activity 1.2.0-alpha02 to handle the startActivityForResult() + onActivityResult() as well as requestPermissions() + onRequestPermissionsResult() flows without overriding methods in your Fragment in addition to providing hooks for testing these flows. See the updated Getting a Result from an Activity . ( b/125158199 )

تغییرات API

  • DialogFragment now provides a constructor that takes a @LayoutRes that indicates the layout that onCreateView() should inflate by default. ( b/150327080 )
  • The onActivityCreated() method is now deprecated. Code touching the fragment's view should be done in onViewCreated() (which is called immediately before onActivityCreated() ) and other initialization code should be in onCreate() . To receive a callback specifically when the activity's onCreate() is complete, a LifeCycleObserver should be registered on the activity's Lifecycle in onAttach() , and removed once the onCreate() callback is received. ( b/144309266 )

رفع اشکالات

  • From Fragment 1.2.3 : Fixed a bug in DialogFragment that caused a StackOverflowError when calling getLayoutInflater() from within onCreateDialog() . ( b/117894767 , aosp/1258664 )
  • From Fragment 1.2.3 : Reduced the scope of Fragment's included ProGuard rules to ensure that unused Fragment classes can be stripped. ( b/149665169 )
  • From Fragment 1.2.3 : Fixed false positives in the UseRequireInsteadOfGet Lint check when using a local variable name that shadowed the Kotlin property name. ( b/149891163 )
  • From Fragment 1.2.3 : FragmentContainerView no longer throws an UnsupportedOperationException for using the incorrect constructor in layout preview. ( b/149707833 )

مشکلات شناخته شده

  • BottomSheetDialogFragment no longer properly positions its dialog on the screen. ( b/151652127 )

Version 1.3.0-alpha01

۴ مارس ۲۰۲۰

androidx.fragment:fragment:1.3.0-alpha01 , androidx.fragment:fragment-ktx:1.3.0-alpha01 , and androidx.fragment:fragment-testing:1.3.0-alpha01 are released. Version 1.3.0-alpha01 contains these commits.

ویژگی‌های جدید

تغییرات API

  • The setRetainInstance() method on Fragments has been deprecated. With the introduction of ViewModels , developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate, avoiding a common source of leaks while maintaining the useful properties of a single creation and destruction of the retained state (namely, the constructor of the ViewModel and the onCleared() callback it receives). ( b/143911815 )
  • With the release of ViewPager2 1.0.0 , the FragmentPagerAdapter and FragmentStatePagerAdapter classes for interacting with ViewPager have been deprecated. See Migrate from ViewPager to ViewPager2 . ( b/145132715 )

رفع اشکالات

  • Fragment ProGuard rules now correctly only keep the default constructors Fragment classes that are used rather than for all Fragment instances, fixing a regression introduced in Fragment 1.2.1 . ( b/149665169
  • The require___() Lint rules added in Fragment 1.2.2 no longer false positive on local variables that share the same name as the shadowed Kotlin property names (ie, view ). ( b/149891163 )
  • FragmentContainerView no longer throws an UnsupportedOperationException when using the layout preview in Android Studio. ( b/149707833 )
  • Fixed an issue where retained fragments that were added after the state is saved would not be continually recreated and then destroyed after each configuration change. ( b/145832397 )

Version 1.2.5

Version 1.2.5

۱۰ ژوئن ۲۰۲۰

androidx.fragment:fragment:1.2.5 , androidx.fragment:fragment-ktx:1.2.5 , and androidx.fragment:fragment-testing:1.2.5 are released. Version 1.2.5 contains these commits.

رفع اشکالات

  • The fragment's getViewLifecycleOwner() is now stopped before onSaveInstanceState() is called, mirroring the behavior of the fragment's lifecycle. This was previously released in Fragment 1.3.0-alpha04 . ( b/154645875 )
  • Calling setMenuVisibility(false) on a fragment now correctly changes the visibility of menus provided by its child fragments. This was previously released in Fragment 1.3.0-alpha04 . ( b/153593580 )

Version 1.2.4

Version 1.2.4

April 1, 2020

androidx.fragment:fragment:1.2.4 , androidx.fragment:fragment-ktx:1.2.4 , and androidx.fragment:fragment-testing:1.2.4 are released. Version 1.2.4 contains these commits.

رفع اشکالات

  • Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. ( b/151605338 )
  • Disabled the FragmentLiveDataObserve Lint rule on DialogFragment classes as their lifecycle and view lifecycle are always in sync, making it safe to use either this or viewLifecycleOwner when calling observe . ( b/151765086 )

Version 1.2.3

Version 1.2.3

۱۸ مارس ۲۰۲۰

androidx.fragment:fragment:1.2.3 , androidx.fragment:fragment-ktx:1.2.3 , and androidx.fragment:fragment-testing:1.2.3 are released. Version 1.2.3 contains these commits.

رفع اشکالات

  • Fixed a bug in DialogFragment that caused a StackOverflowError when calling getLayoutInflater() from within onCreateDialog() . ( b/117894767 , aosp/1258665 )
  • Reduced the scope of Fragment's included ProGuard rules to ensure that unused Fragment classes can be stripped. ( b/149665169 )
  • Fixed false positives in the UseRequireInsteadOfGet Lint check when using a local variable name that shadowed the Kotlin property name. ( b/149891163 )
  • FragmentContainerView no longer throws an UnsupportedOperationException for using the incorrect constructor in layout preview. ( b/149707833 )

Version 1.2.2

Version 1.2.2

۱۹ فوریه ۲۰۲۰

androidx.fragment:fragment:1.2.2 , androidx.fragment:fragment-ktx:1.2.2 , and androidx.fragment:fragment-testing:1.2.2 are released. Version 1.2.2 contains these commits.

New Lint checks

  • Lint suggests using the viewLifecycleOwner as the LifecycleOwner to calls into OnBackPressedDispatcher in onCreateView() , onViewCreated() , and onActivityCreated() . ( b/142117657 )
  • Added a new Lint check that confirms that you are using the correct debugImplementation when using the fragment-testing artifact. ( b/141500106 )
  • Fragments now suggest using the associated require___() methods for more descriptive error messages instead of checkNotNull(get___()) , requireNonNull(get___()) , or get___()!! for all of the Fragment APIs that include both a get and require equivalent. ( aosp/1202883 )

رفع اشکالات

  • Fixed the Fragment ProGuard files to avoid R8 warnings ( b/148963981 )
  • Improved the existing Lint check suggesting using viewLifecycleOwner when using observe to also handle the livedata-ktx extension method version of observe . ( b/148996309 )
  • Fixed the formatting for many of the Lint checks ( aosp/1157012 )

External contributions

  • Thanks to Zac Sweers for contributing the require___() Lint checks on behalf of Slack! ( aosp/1202883 )

Version 1.2.1

Version 1.2.1

February 5, 2020

androidx.fragment:fragment:1.2.1 , androidx.fragment:fragment-ktx:1.2.1 , and androidx.fragment:fragment-testing:1.2.1 are released. Version 1.2.1 contains these commits .

رفع اشکالات

  • Fragments added via the add and replace methods that take a Class instance (or the Kotlin reified versions) now have their default constructor kept by ProGuard. ( b/148181315 )
  • FragmentStatePagerAdapter and FragmentPagerAdapter no longer catch exceptions thrown by FragmentManager when running finishUpdate() . ( aosp/1208711 )
  • Fixed an issue where FragmentManager.findFragment() did not work with fragments added via the <fragment> tag. ( b/147784323 )
  • Fragments inflated using the <fragment> tag now always receive a call to onInflate() before onCreate() when in the layout. ( aosp/1215856 )
  • Calling toString() on a FragmentManager instance no longer throws a NullPointerException when the Activity is already destroyed. ( b/148189412 )

Dependency changes

نسخه ۱.۲.۰

نسخه ۱.۲.۰

۲۲ ژانویه ۲۰۲۰

androidx.fragment:fragment:1.2.0 , androidx.fragment:fragment-ktx:1.2.0 , and androidx.fragment:fragment-testing:1.2.0 are released. Version 1.2.0 contains these commits .

Important changes since 1.1.0

  • FragmentContainerView : The FragmentContainerView is the strongly recommended container for dynamically added Fragments, replacing usage of FrameLayout or other layouts. It also supports the same class , android:name , and optional android:tag as the <fragment> tag, but uses a normal FragmentTransaction to add this initial fragment, instead of the custom code path used by <fragment> .
  • onDestroyView() timing : Fragments now wait for exit animations, exit framework transitions, and exit AndroidX transitions (when using Transition 1.3.0 ) to complete before calling onDestroyView() .
  • Class based add() and replace() : Added new overloads of add() and replace() on FragmentTransaction that take a Class<? extends Fragment> and optional Bundle of arguments. These methods use your FragmentFactory to construct an instance of the Fragment to add. Kotlin extensions that use reified types (ie, fragmentTransaction.replace<YourFragment>(R.id.container) ) have also been added to fragment-ktx .
  • Lifecycle ViewModel SavedState Integration : SavedStateViewModelFactory is now the default factory used when using by viewModels() , by activityViewModels() , the ViewModelProvider constructor, or ViewModelProviders.of() with a Fragment.
  • New Lint checks : Added a new Lint check that ensures you are using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() .
  • getFragmentManager() deprecation : The getFragmentManager() and requireFragmentManager() methods on Fragment have been deprecated and replaced with a single getParentFragmentManager() method, which returns the non-null FragmentManager the Fragment is added to (you can use isAdded() to determine if it is safe to call).
  • FragmentManager.enableDebugLogging() deprecation : The static FragmentManager.enableDebugLogging method has been deprecated. FragmentManager now respects Log.isLoggable() for the tag FragmentManager , allowing you to enable either DEBUG or VERBOSE logging without re-compiling your app.

مشکلات شناخته شده

  • Fragments referenced only via the class or android:name attribute on a FragmentContainerView are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. ( b/142601969 )
  • When adding a NavHostFragment using class or android:name in XML with FragmentContainerView , you cannot use findNavController() in onCreate() of your Activity. ( b/142847973 )

Version 1.2.0-rc05

۸ ژانویه ۲۰۲۰

androidx.fragment:fragment:1.2.0-rc05 , androidx.fragment:fragment-ktx:1.2.0-rc05 , and androidx.fragment:fragment-testing:1.2.0-rc05 are released. Version 1.2.0-rc05 contains these commits .

رفع اشکالات

  • Fixed a regression in Fragment 1.2.0-rc04 when using the <fragment> tag which caused onViewCreated() to be called incorrectly during activity destruction. ( b/146290333 )
  • Fragments added with the <fragment> tag now properly have their non-config cleared even when they are only sometimes in the layout (ie, only in your landscape layout). As a consequence, these Fragments are now correctly moved to CREATED even when not in your layout instead of being instantiated but never moving through any lifecycle methods. ( b/145769287 )

Version 1.2.0-rc04

December 18, 2019

androidx.fragment:fragment:1.2.0-rc04 , androidx.fragment:fragment-ktx:1.2.0-rc04 , and androidx.fragment:fragment-testing:1.2.0-rc04 are released. Version 1.2.0-rc04 contains these commits .

رفع اشکالات

  • Adjusted the animations for TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , and TRANSIT_FRAGMENT_FADE to avoid visual issues. ( b/145468417 )

Version 1.2.0-rc03

۴ دسامبر ۲۰۱۹

androidx.fragment:fragment:1.2.0-rc03 , androidx.fragment:fragment-ktx:1.2.0-rc03 , and androidx.fragment:fragment-testing:1.2.0-rc03 are released. Version 1.2.0-rc03 contains these commits .

رفع اشکالات

  • Fixed an unintentional behavior change where Fragments who have been removed are still returned by findFragmentById() / findFragmentByTag() while their exit animations/transitions run. ( b/143982969 , aosp/1167585 )
  • Child fragments are now correctly stopped before their parents when the containing activity calls onSaveInstanceState() . ( b/144380645 )
  • Fixed an issue where Views were incorrectly marked INVISIBLE after popping a hidden Fragment. ( b/70793925 )
  • Fragment shared element transitions now handle Views that have been rotated, scaled, etc. ( b/142835261 )

Documentation Updates

  • Clarified the deprecation documentation around setUserVisibleHint() . ( b/143897055 )
  • Improved the documentation on setFragmentFactory() and getFragmentFactory() to better indicate that setting a FragmentFactory will also affect child FragmentManagers. ( aosp/1170095 )

Dependency changes

  • Fragments now depends on Lifecycle 2.2.0-rc03 , Lifecycle ViewModel SavedState 1.0.0-rc03 , and Activity 1.1.0-rc03 .

Version 1.2.0-rc02

۷ نوامبر ۲۰۱۹

androidx.fragment:fragment:1.2.0-rc02 , androidx.fragment:fragment-ktx:1.2.0-rc02 , and androidx.fragment:fragment-testing:1.2.0-rc02 are released. Version 1.2.0-rc02 contains these commits .

رفع اشکالات

  • When in Kotlin, the LintFix for using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() (introduced in Fragment 1.2.0-rc01 ) now uses the Kotlin property access syntax viewLifecycleOwner instead of getViewLifecycleOwner() . ( aosp/1143821 )

Version 1.2.0-rc01

۲۳ اکتبر ۲۰۱۹

androidx.fragment:fragment:1.2.0-rc01 , androidx.fragment:fragment-ktx:1.2.0-rc01 , and androidx.fragment:fragment-testing:1.2.0-rc01 are released. Version 1.2.0-rc01 contains these commits .

ویژگی‌های جدید

  • FragmentContainerView now supports the class attribute in addition to android:name , mirroring the functionality of the <fragment> tag. ( b/142722242 )
  • Added a new Lint check that ensures you are using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() . ( b/137122478 )

رفع اشکالات

  • The onDismiss and onCancel callbacks on DialogFragment now guarantee that the DialogInterface passed to them is non-null and that getDialog() returns non-null when they are executed. ( b/141974033 )
  • FragmentContainerView now adds the Fragment defined by class or android:name as part of inflation, ensuring that findFragmentById() and findFragmentByTag() work immediately afterwards. ( b/142520327 )
  • Fixed an IllegalStateException in FragmentContainerView due to the state being saved. ( b/142580713 )
  • Fixed an UnsupportedOperationException in FragmentContainerView when the FragmentContainerView class is obfuscated. ( b/142657034 )

مشکلات شناخته شده

  • Fragments referenced only via the class or android:name attribute on a FragmentContainerView are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. We have disabled the Lint rule suggesting moving to FragmentContainerView until this is fixed via aapt2 . ( b/142601969 )

Version 1.2.0-beta02

October 11, 2019

androidx.fragment:fragment:1.2.0-beta02 , androidx.fragment:fragment-ktx:1.2.0-beta02 , and androidx.fragment:fragment-testing:1.2.0-beta02 are released. Version 1.2.0-beta02 contains these commits .

رفع اشکالات

  • Fixed an issue where Fragment's onInflate() did not receive proper attributes from FragmentContainerView , breaking cases such as NavHostFragment . ( b/142421837 )

Version 1.2.0-beta01

۹ اکتبر ۲۰۱۹

androidx.fragment:fragment:1.2.0-beta01 , androidx.fragment:fragment-ktx:1.2.0-beta01 , and androidx.fragment:fragment-testing:1.2.0-beta01 are released. Version 1.2.0-beta01 contains these commits .

ویژگی‌های جدید

  • FragmentContainerView adds support for adding an initial fragment with added support for the android:name and optional android:tag XML attributes. Unlike the <fragment> tag, FragmentContainerView uses a normal FragmentTransaction under the hood to add the initial fragment, allowing further FragmentTransaction operations on the FragmentContainerView and enables the usage of View Binding for the layout. ( b/139830628 , b/141177981 )
  • Fragments now contains a Lint warning offering a quick fix to replace <fragment> with FragmentContainerView . ( b/139830056 )

رفع اشکالات

  • Fixed a ClassCastException when using androidx.transition . ( b/140680619 )
  • When using Transition 1.3.0-beta01 , Fragments now wait for androidx.transition transitions (in addition to framework transitions and animations, which were fixed in Fragment 1.2.0-alpha03 and Fragment 1.2.0-alpha02 , respectively) to finish before dispatching onDestroyView() . ( aosp/1119841 )
  • When using Transition 1.3.0-beta01 , Fragments now properly cancel androidx.transition transitions before starting new transitions / animations on the same container. ( aosp/1119841 )
  • Fixed an issue on API 17 and lower when using androidx.transition transitions on the root view of your Fragment when using FragmentContainerView . ( b/140361893 )
  • The fragment-testing artifact now depends on AndroidX Test 1.2.0 , fixing an incompatibility with the latest Espresso 3.2.0. ( b/139100149 )
  • Removed usage of Log.w in FragmentManager. ( aosp/1126468 )

مشکلات شناخته شده

  • Fragment's onInflate() do not receive proper attributes from FragmentContainerView , breaking cases such as NavHostFragment . ( b/142421837 )

Version 1.2.0-alpha04

September 18, 2019

androidx.fragment:fragment:1.2.0-alpha04 , androidx.fragment-ktx:example:1.2.0-alpha04 , and androidx.fragment:fragment-testing:1.2.0-alpha04 are released. Version 1.2.0-alpha04 contains these commits .

API changes

  • The getFragmentManager() and requireFragmentManager() methods on Fragment have been deprecated and replaced with a single getParentFragmentManager() method, which returns the non-null FragmentManager the Fragment is added to (you can use isAdded() to determine if it is safe to call). ( b/140574496 )
  • The static FragmentManager.enableDebugLogging method has been deprecated. FragmentManager now respects Log.isLoggable() for the tag FragmentManager , allowing you to enable either DEBUG or VERBOSE logging without re-compiling your app. ( aosp/1116591 )

رفع اشکالات

  • Fragments are now properly destroyed while exit animations on other fragments are running. ( b/140574199 )
  • Fixed an issue where Fragments would call Activity.findViewById() where before it did not. ( aosp/1116431 )

Version 1.2.0-alpha03

۵ سپتامبر ۲۰۱۹

androidx.fragment:fragment:1.2.0-alpha03 , androidx.fragment:fragment-ktx:1.2.0-alpha03 , and androidx.fragment:fragment-testing:1.2.0-alpha03 are released. The commits included in this version can be found here .

API changes

رفع اشکالات

  • FragmentContainerView now properly reverses the draw order when popping fragments off the back stack. ( b/139104187 )
  • Fixed an issue where the wrong animation would run when both popping a fragment and adding a new fragment at the same time. ( b/111659726 )
  • Fragments now wait for transitions (in addition to animations, which was fixed in Fragment 1.2.0-alpha02 ) to finish before dispatching onDestroyView() . ( b/138741697 )

Version 1.2.0-alpha02

August 7, 2019

androidx.fragment:fragment:1.2.0-alpha02 , androidx.fragment:fragment-ktx:1.2.0-alpha02 , and androidx.fragment:fragment-testing:11.2.0-alpha02 is released. The commits included in this version can be found here .

ویژگی‌های جدید

  • SavedStateViewModelFactory is now the default factory used when using by viewModels() , by activityViewModels() , the ViewModelProvider constructor, or ViewModelProviders.of() with a Fragment . ( b/135716331 )
  • The default animations when using TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , TRANSIT_FRAGMENT_FADE with setTransition on a FragmentTransaction have been updated to match the animations used by activities on Android 10 devices. ( aosp/1012812 , aosp/1014730 )

API changes

  • Introduces FragmentContainerView as the strongly recommended container for dynamically added Fragments, replacing usage of FrameLayout , etc. as it fixes animation z-ordering issues and window insets dispatching to Fragments. ( b/37036000 , aosp/985243 , b/136494650 )
  • Added a static FragmentManager.findFragment(View) method to retrieve the containing Fragment from a view inflated by a fragment. A Kotlin extension is also available in fragment-ktx . ( aosp/1090757 )
  • Added new overloads of add() and replace() on FragmentTransaction that take a Class<? extends Fragment> and optional Bundle of arguments. These methods use your FragmentFactory to construct an instance of the Fragment to add. Kotlin extension that use reified types (ie, fragmentTransaction.replace<YourFragment>(R.id.container) ) have also been added to fragment-ktx . ( b/126124987 )
  • @MainThread annotations have been added to Fragment lifecycle callbacks. ( b/127272564 )
  • The breadcrumb title related APIs on FragmentTransaction and FragmentManager.BackStackEntry have been deprecated. ( b/138252944 )
  • The setTransitionStyle method on FragmentTransaction has been deprecated. ( aosp/1011537 )
  • Many of the methods in FragmentManager are no longer abstract . FragmentManager itself remains abstract and should not be directly instantiated or extended; you should continue to only get an existing instance from getSupportFragmentManager() , getChildFragmentManager() , etc.

رفع اشکالات

  • From Fragment 1.1.0-rc04 : Fragments now correctly cancel postponed transitions on Fragments have been popped. ( b/138251858 )
  • From Fragment 1.1.0-rc03 : Fixed an issue where calling postponeEnterTransition() with a timeout more than once would not cancel previous timeouts. ( b/137797118 )
  • From Fragment 1.1.0-rc02 : Fixed a crash in FragmentPagerAdapter and FragmentStatePagerAdapter when removing the current item. ( b/137209870 )
  • Fragments now wait for animations to finish before dispatching onDestroyView() . ( b/136110528 )
  • Fragment animations from child fragments and their descendants are now properly handled when animating the parent Fragment. ( b/116675313 )
  • Fixed a NullPointerException when using shared element transitions and combining a pop and add operation. ( b/120507394 )
  • Added a workaround to IllegalStateException s when using FragmentPagerAdapter and FragmentStatePagerAdapter in Robolectric tests. ( b/137201343 )

Version 1.2.0-alpha01

July 2, 2019

androidx.fragment:fragment:1.2.0-alpha01 , androidx.fragment:fragment-ktx:1.2.0-alpha01 , and androidx.fragment:fragment-testing:1.2.0-alpha01 are released. The commits included in this version can be found here .

ویژگی‌های جدید

  • FragmentManager now calls requestApplyInsets() after attaching the Fragment's view and directly before calling onViewCreated() , ensuring that your view always has the correct insets. ( b/135945162 )

رفع اشکالات

  • Fixed a NullPointerException when popping a FragmentTransaction that used setPrimaryNavigationFragment() before replace() . ( b/134673465 )

نسخه ۱.۱.۰

نسخه ۱.۱.۰

۵ سپتامبر ۲۰۱۹

androidx.fragment:fragment:1.1.0 , androidx.fragment:fragment-ktx:1.1.0 , and androidx.fragment:fragment-testing:1.1.0 are released. The commits included in this version can be found here .

Important Changes since 1.0.0

  • fragment-testing : The fragment-testing artifact provides a FragmentScenario class for testing a fragment in isolation. See Test your app's fragments documentation for more details.
  • FragmentFactory : You can now set a FragmentFactory on a FragmentManager to manage the creation of fragment instances, removing the strict requirement to have a no-argument constructor.
  • Kotlin Property Delegates for ViewModels : The fragment-ktx artifact now contains two Kotlin property delegates: by viewModels() for accessing ViewModels associated with the individual fragment and by activityViewModels() for accessing ViewModels scoped to the activity.
  • Max Lifecycle : You can now set a max Lifecycle state for a Fragment by calling setMaxLifecycle() on a FragmentTransaction . This replaces the now deprecated setUserVisibleHint() . FragmentPagerAdapter and FragmentStatePagerAdapter have a new constructor that allows you to switch to the new behavior.
  • FragmentActivity LayoutId constructor : Subclasses of FragmentActivity can now optionally call into a constructor on FragmentActivity that takes an R.layout ID, indicating the layout that should be set as the content view as an alternative to calling setContentView() in onCreate() . This does not change the requirement that your subclass have a no-argument constructor.
  • Fragment LayoutId constructor : Subclasses of Fragment can now optionally call into a constructor on Fragment that takes an R.layout ID, indicating the layout that should be used for this fragment as an alternative to overriding onCreateView() . The inflated layout can be configured in onViewCreated() .
  • Postpone with a timeout : A new overload of postponeEnterTransition() has been added that takes a timeout.

Version 1.1.0-rc04

August 7, 2019

androidx.fragment:fragment:1.1.0-rc04 , androidx.fragment:fragment-ktx:1.1.0-rc04 , and androidx.fragment:fragment-testing:1.1.0-rc04 is released. The commits included in this version can be found here .

رفع اشکالات

  • Fragments now correctly cancel postponed transitions on Fragments have been popped. ( b/138251858 )

Version 1.1.0-rc03

۱۹ ژوئیه ۲۰۱۹

androidx.fragment:fragment:1.1.0-rc03 , androidx.fragment:fragment-ktx:1.1.0-rc03 , and androidx.fragment:fragment-testing:1.1.0-rc03 is released. The commits included in this version can be found here .

رفع اشکالات

  • Fixed an issue where calling postponeEnterTransition() with a timeout more than once would not cancel previous timeouts. ( b/137797118 )

Version 1.1.0-rc02

۱۷ ژوئیه ۲۰۱۹

androidx.fragment:fragment:1.1.0-rc02 , androidx.fragment:fragment-ktx:1.1.0-rc02 , and androidx.fragment-testing:fragment:1.1.0-rc02 are released. The commits included in this version can be found here .

رفع اشکالات

  • Fixed a crash in FragmentPagerAdapter and FragmentStatePagerAdapter when removing the current item. ( b/137209870 )

نسخه ۱.۱.۰-rc01

July 2, 2019

androidx.fragment:fragment:1.1.0-rc01 , androidx.fragment:fragment-ktx:1.1.0-rc01 , and androidx.fragment:fragment-testing:1.1.0-rc01 are released. The commits included in this version can be found here .

رفع اشکالات

  • Fragments now properly update their visibility when using show() or hide() operations while the transition is running. ( b/133385058 )
  • Fixed a NullPointerException when popping a FragmentTransaction that used setPrimaryNavigationFragment() before replace() . ( b/134673465 )

نسخه ۱.۱.۰-بتا۰۱

۵ ژوئن ۲۰۱۹

androidx.fragment:fragment:1.1.0-beta01 , androidx.fragment:fragment-ktx:1.1.0-beta01 , and androidx.fragment:fragment-testing:1.1.0-beta01 are released. The commits included in this version can be found here .

رفع اشکالات

  • androidx.lifecycle.Lifecycle callbacks (specifically related to STARTED , RESUMED , PAUSED , STOPPED , and DESTROYED ) for nested Fragments are now properly nested. ( b/133497591 )
  • OnBackPressedCallback instances registered in a Fragment's onCreate() now properly take precedence over the child FragmentManager. ( b/133175997 )
  • Child fragments are no longer animated when their parent fragment is being replaced. ( b/121017790 )
  • Fragments animations and transitions are now ignored when using animateLayoutChanges="true" , fixing an issue where Fragments were not properly destroyed. ( b/116257087 )

Version 1.1.0-alpha09

۱۶ مه ۲۰۱۹

androidx.fragment:fragment:1.1.0-alpha09 , androidx.fragment:fragment-ktx:1.1.0-alpha09 , and androidx.fragment:fragment-testing:1.1.0-alpha09 are released. The commits included in this version can be found here .

API changes

  • Fragments now receive a callback to a new onPrimaryNavigationFragmentChanged(boolean) method when the primary navigation fragment changes. aosp/960857

رفع اشکالات

  • Menu Items inflated by a child Fragment are now correctly removed when the Parent Fragment is removed. b/131581013

Version 1.1.0-alpha08

۷ مه ۲۰۱۹

androidx.fragment:fragment:1.1.0-alpha08 , androidx.fragment:fragment-ktx:1.1.0-alpha08 , and androidx.fragment:fragment-testing:1.1.0-alpha08 are released. The commits included in this version can be found here .

This release is incompatible with Preferences 1.1.0-alpha01 through 1.1.0-alpha04. Please upgrade to Preferences 1.1.0-alpha05 when using this version of Fragments.

ویژگی‌های جدید

  • Added a new overload of postponeEnterTransition() that takes a timeout, after which the Fragment will automatically call startPostponedEnterTransition() b/120803208

API changes

  • Breaking change: the previously deprecated FragmentFactory instantiate method that took a Bundle has been removed. aosp/953856
  • Breaking change: The RESUME_ONLY_CURRENT_FRAGMENT and USE_SET_USER_VISIBLE_HINT constants in FragmentPagerAdapter and FragmentStatePagerAdapter have been renamed to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT and BEHAVIOR_SET_USER_VISIBLE_HINT , respectively. aosp/954782

رفع اشکالات

  • Fragments that have had their lifecycle capped via setMaxLifecycle() no longer get resumed before reaching their final state. b/131557151
  • When using setMaxLifecycle(Lifecycle.State.CREATED) , Fragments will properly have their view destroyed. aosp/954180

Version 1.1.0-alpha07

۲۵ آوریل ۲۰۱۹

androidx.fragment:fragment:1.1.0-alpha07 , androidx.fragment:fragment-ktx:1.1.0-alpha07 , and androidx.fragment:fragment-testing:1.1.0-alpha07 are released. The commits included in this version can be found here .

ویژگی‌های جدید

  • You can now set a max Lifecycle state for a Fragment by calling setMaxLifecycle() on a FragmentTransaction . This replaces the now deprecated setUserVisibleHint() . FragmentPagerAdapter and FragmentStatePagerAdapter have a new constructor that allows you to switch to the new behavior. ( b/129780800 )

تغییرات API

  • moveToState(STARTED) on FragmentScenario can now only be called on API 24+ devices. ( b/129880016 )

تغییرات رفتاری

  • As a consequence of ( b/129907905 ), fragments on the back stack will not get a callback to onCreateView() when the hosting activity is recreated. onCreateView() will now only be called when the fragment becomes visible (ie, the back stack is popped).

رفع اشکالات

  • Fixed an issue when using a <fragment> tag in XML and the contentLayoutId constructor of FragmentActivity or AppCompatActivity . ( b/129907905 )
  • Corrected an issue where fragments on the back stack would not be moved to at least CREATED after a configuration change, causing ViewModels and child retained fragments to not be properly disposed. ( b/129593351 )
  • Fixed a crash in restoreSaveState caused by a desync of the retained fragments after the instance state is saved. ( b/130433793 ) ( aosp/947824 )
  • Fixed issues where an OnBackPressedCallback added with a fragment lifecycle would not be called if the FragmentManager had a back stack. See androidx.activity 1.0.0-alpha07 for more details. ( aosp/948209 )
  • Fragments no longer enforce LAYER_TYPE_HARDWARE for animations. If you specifically need a hardware layer animation, please set it as part of your animation. ( b/129486478 )

Version 1.1.0-alpha06

April 3, 2019

androidx.fragment:fragment:1.1.0-alpha06 , androidx.fragment:fragment-ktx:1.1.0-alpha06 , and androidx.fragment:fragment-testing:1.1.0-alpha06 are released. The commits included in this version can be found here .

ویژگی‌های جدید

  • Exceptions thrown by FragmentManager now include the Fragment's name in the message. ( b/67759402 )

تغییرات API

  • Fragment and FragmentActivity now contain a second constructor that takes a @LayoutRes int , which replaces the previous behavior of annotating your class with @ContentView . This approach works in both app and library modules. ( b/128352521 )
  • FragmentActivity's onActivityResult() is now properly marked as @CallSuper . ( b/127971684 )
  • The FragmentFactory's instantiate method that takes an argument Bundle has been deprecated and apps should use the new instantiate overload that does not take a Bundle. ( b/128836103 )
  • FragmentScenario methods are now properly annotated with @StyleRes . ( aosp/924193 )
  • FragmentTabHost has been deprecated. ( b/127971835 )
  • FragmentActivity's getThemedContext() has been removed. ( aosp/934078 )

رفع اشکالات

  • Fixed a regression in 1.1.0-alpha05 that caused the incoming Fragment to flash on the screen. ( b/129405432 )
  • Fixed an issue where the primary navigation fragment would be lost after a popBackStack+replace+popBackStack series of operations. ( b/124332597 )
  • Fixed an issue when using @ContentView constructors on your Activity when restoring Fragment state. ( b/127313094 )
  • Corrected the logic of setTargetFragment() when replacing an existing target Fragment with a Fragment not yet attached to the FragmentManager. ( aosp/932156 )

Version 1.1.0-alpha05

۱۳ مارس ۲۰۱۹

androidx.fragment:fragment:1.1.0-alpha05 , androidx.fragment:fragment-ktx:1.1.0-alpha05 , and androidx.fragment:fragment-testing:1.1.0-alpha05 are released. The full list of commits included in this version can be found here .

ویژگی‌های جدید

  • @ContentView annotation lookups are now cached ( b/123709449 )

تغییرات رفتاری

  • Calling remove() , hide() , show() , detach() , and setPrimaryNavigationFragment() with a Fragment attached to a different FragmentManager now throws an IllegalStateException rather than silently failing ( aosp/904301 )

رفع اشکالات

  • onNewIntent for FragmentActivity is now correctly marked with @CallSuper ( b/124120586 )
  • Fixed an issue where DialogFragment 's onDismiss() could be called twice when using getDialog().dismiss() or getDialog().cancel() ( b/126563750 )

Version 1.1.0-alpha04

۷ فوریه ۲۰۱۹

androidx.fragment:fragment 1.1.0-alpha04 , androidx.fragment:fragment-ktx 1.1.0-alpha04 , and androidx.fragment:fragment-testing 1.1.0-alpha04 are released.

ویژگی‌های جدید

  • Added support for the @ContentView class annotation that allows you to indicate which layout XML file should be inflated as an alternative to overriding onCreateView() . It is recommended to do view related work in onViewCreated() . ( aosp/837619 )
  • fragment-testing now depends on androidx.test:core-ktx 1.1.0 stable ( b/121209673 )
  • You can now use openActionBarOverflowOrOptionsMenu with FragmentScenario to test Fragment hosted options menus ( b/121126668 )

API changes

  • Added a requireArguments() method which returns a @NonNull Bundle or throws an IllegalStateException ( b/121196360 )
  • Added a note that getLifecycle() , getViewLifecycleOwner() , and getViewLifecycleOwnerLiveData() should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. ( aosp/880714 )
  • Added a note that getViewModelStore() should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. ( aosp/880713 )
  • Fixed an issue with binary compatibility with previous releases of Fragments. ( aosp/887877 ) ( aosp/889834 )

رفع اشکالات

  • Target fragments are correctly cleared out when you pass null to setTargetFragment() . ( aosp/849969 )
  • Fixed an issue where target Fragments were sometimes unavailable in or after onDestroy() . ( b/122312935 )
  • DialogFragment's onDismiss() is now called before onDestroy() . ( aosp/874133 ) ( aosp/890734 )

Version 1.1.0-alpha03

December 17, 2018

ویژگی‌های جدید

  • Fragment now implements BundleSavedStateRegistryOwner and depends on the newly released SavedState library [ aosp/824380 ]
  • A by activityViewModels Kotlin property delegate has been added to retrieve ViewModels associated with the containing Activity [ b/119050253 ]
  • The by viewModels Kotlin property delegate has been expanded to take an optional lambda method for getting the ViewModelStoreOwner , allowing you to pass in the parent Fragment or other custom ViewModelStoreOwner with code such as val viewModel: MyViewModel by viewModels(::requireParentFragment) [ b/119050253 ]

API changes

  • FragmentScenario now allows you to specify a theme such as Theme.AppCompat [ b/119054431 ]. This is a breaking change.
  • Added a requireView() method which returns a @NonNull View or throws an IllegalStateException [ b/120241368 ]
  • Added a requireParentFragment() method which returns a @NonNull Fragment or throws an IllegalStateException [ b/112103783 ]

رفع اشکالات

  • Fixed IllegalStateException: Failure saving state b/120814739
  • Fragments being restored from saved instance state will now always receive a non-null Bundle [ b/119794496 ]
  • Removed Fragments no longer reuse their Lifecycle object if re-added [ b/118880674 ]

Version 1.1.0-alpha02

۳ دسامبر ۲۰۱۸

ویژگی‌های جدید

  • FragmentScenario's Kotlin extensions now let you use a lambda for Fragment construction as an alternative to passing in a FragmentFactory instance. ( aosp/812913 )

رفع اشکالات

  • Fixed an IllegalStateException when using nested Fragments on the back stack ( b/119256498 )
  • Fixed crash when using FragmentScenario.recreate() with a FragmentFactory ( aosp/820540 )
  • Fixed an issue where target Fragments were not accessible after the Fragment was removed ( aosp/807634 )

نسخه ۱.۱.۰-آلفا۰۱

November 5, 2018

This is the first release of the fragment-testing artifact and FragmentScenario which is built on top of the androidx.test:core APIs. See the Fragment testing documentation for more details.

ویژگی‌های جدید

  • New FragmentScenario class for testing Fragments in isolation.
  • You can now set a FragmentFactory on any FragmentManager to control how new Fragment instances are instantiated.
  • Added a new by viewModels() Kotlin property delegate for retrieving ViewModels from a Fragment.
  • Pending input events (such as clicks) are now canceled in a Fragment's onStop() .

API changes

  • Significantly expanded the nullability annotations across the Fragment API surface.

رفع اشکالات

  • Fix an issue which caused Fragment operations to fail from within LiveData (b/77944637)

مشکلات شناخته شده

  • Target Fragments cannot be accessed after a Fragment has been removed from the FragmentManager.
  • fragment-testing depends on androidx.test:core:1.0.0-beta01 instead of the correct androidx.test:core:1.0.0 .