چرخه حیات
این جدول تمام مصنوعات موجود در گروه androidx.lifecycle را فهرست میکند.
| مصنوع | انتشار پایدار | کاندیدای انتشار | انتشار بتا | انتشار آلفا |
|---|---|---|---|---|
| چرخه حیات-* | ۲.۹.۴ | ۲.۱۰.۰-rc01 | - | - |
| چرخه عمر-viewmodel-navigation3 | - | ۲.۱۰.۰-rc01 | - | - |
اعلام وابستگیها
برای افزودن یک وابستگی به Lifecycle، باید مخزن Google Maven را به پروژه خود اضافه کنید. برای اطلاعات بیشتر، مخزن Google's Maven را مطالعه کنید.
وابستگیهای مربوط به مصنوعات مورد نیاز خود را در فایل build.gradle برای برنامه یا ماژول خود اضافه کنید:
کاتلین
شیار
dependencies { def lifecycle_version = "2.9.4" def arch_version = "2.2.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // ViewModel utilities for Compose implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" // Lifecycle utilities for Compose implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version" // Saved state module for ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" // ViewModel integration with Navigation3 implementation "androidx.lifecycle:lifecycle-viewmodel-navigation3:2.10.0-rc01" // Annotation processor kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" // alternately - if using Java8, use the following instead of lifecycle-compiler implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // optional - helpers for implementing LifecycleOwner in a Service implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version" // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version" // optional - ReactiveStreams support for LiveData implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version" // optional - Test helpers for LiveData testImplementation "androidx.arch.core:core-testing:$arch_version" // optional - Test helpers for Lifecycle runtime testImplementation "androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version" }
کاتلین
dependencies { val lifecycle_version = "2.9.4" val arch_version = "2.2.0" // ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") // ViewModel utilities for Compose implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version") // LiveData implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") // Lifecycles only (without ViewModel or LiveData) implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version") // Lifecycle utilities for Compose implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version") // Saved state module for ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version") // ViewModel integration with Navigation3 implementation("androidx.lifecycle:lifecycle-viewmodel-navigation3:2.10.0-rc01") // Annotation processor kapt("androidx.lifecycle:lifecycle-compiler:$lifecycle_version") // alternately - if using Java8, use the following instead of lifecycle-compiler implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version") // optional - helpers for implementing LifecycleOwner in a Service implementation("androidx.lifecycle:lifecycle-service:$lifecycle_version") // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation("androidx.lifecycle:lifecycle-process:$lifecycle_version") // optional - ReactiveStreams support for LiveData implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version") // optional - Test helpers for LiveData testImplementation("androidx.arch.core:core-testing:$arch_version") // optional - Test helpers for Lifecycle runtime testImplementation ("androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version") }
جاوا
شیار
dependencies { def lifecycle_version = "2.9.4" def arch_version = "2.2.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" // Saved state module for ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" // Annotation processor annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" // alternately - if using Java8, use the following instead of lifecycle-compiler implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // optional - helpers for implementing LifecycleOwner in a Service implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version" // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version" // optional - ReactiveStreams support for LiveData implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version" // optional - Test helpers for LiveData testImplementation "androidx.arch.core:core-testing:$arch_version" // optional - Test helpers for Lifecycle runtime testImplementation "androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version" }
کاتلین
dependencies { val lifecycle_version = "2.9.4" val arch_version = "2.2.0" // ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version") // LiveData implementation("androidx.lifecycle:lifecycle-livedata:$lifecycle_version") // Lifecycles only (without ViewModel or LiveData) implementation("androidx.lifecycle:lifecycle-runtime:$lifecycle_version") // Saved state module for ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version") // Annotation processor annotationProcessor("androidx.lifecycle:lifecycle-compiler:$lifecycle_version") // alternately - if using Java8, use the following instead of lifecycle-compiler implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version") // optional - helpers for implementing LifecycleOwner in a Service implementation("androidx.lifecycle:lifecycle-service:$lifecycle_version") // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation("androidx.lifecycle:lifecycle-process:$lifecycle_version") // optional - ReactiveStreams support for LiveData implementation("androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version") // optional - Test helpers for LiveData testImplementation("androidx.arch.core:core-testing:$arch_version") // optional - Test helpers for Lifecycle runtime testImplementation("androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version") }
برای اطلاعات بیشتر در مورد وابستگیها، به بخش «افزودن وابستگیهای ساخت» مراجعه کنید.
بازخورد
بازخورد شما به بهبود Jetpack کمک میکند. اگر مشکلات جدیدی کشف کردید یا ایدههایی برای بهبود این کتابخانه دارید، به ما اطلاع دهید. لطفاً قبل از ایجاد یک کتابخانه جدید، نگاهی به مشکلات موجود در این کتابخانه بیندازید. میتوانید با کلیک بر روی دکمه ستاره، رأی خود را به یک مشکل موجود اضافه کنید.
برای اطلاعات بیشتر به مستندات ردیاب مشکل مراجعه کنید.
نسخه ۲.۱۰
نسخه ۲.۱۰.۰-rc01
۵ نوامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-rc01 منتشر شد. نسخه 2.10.0-rc01 شامل این کامیتها است.
نسخه ۲.۱۰.۰-بتا۰۱
۲۲ اکتبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-beta01 منتشر شد. نسخه 2.10.0-beta01 شامل این کامیتها است.
تغییرات API
-
ViewModelStoreNavEntryDecoratorDefaultبهViewModelStoreNavEntryDecoratorDefaultsتغییر نام داده شده است، به همراه یک 's' ( I6d27b ، b/444447434 )
رفع اشکالات
- اگر مالک قبل از انتقال به
Lifeycle.State.CREATED، رویدادLifecycle.Event.ON_DESTROYدریافت کند،rememberLifecycleOwnerدیگر از کار نمیافتد ( I6f98e ، b/444594991 ).
نسخه ۲.۱۰.۰-آلفا۰۵
۸ اکتبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha05 منتشر شد. نسخه 2.10.0-alpha05 شامل این کامیتها است.
تغییرات API
- تابع
removeViewModelStoreOnPopCallback()اکنون بخشی از شیءViewModelStoreNavEntryDecoratorDefaultاست که در آن سایر پلتفرمها و پیادهسازیها میتوانند مقدار پیشفرض را فراخوانی کنند. ( Ia1f23 , b/444447434 ) -
ViewModelStoreNavEntryDecoratorاز یک تابع به یک کلاس تغییر داده تا عملکرد آن را به عنوان یک factory برایNavEntryDecoratorبهتر منعکس کند، و پارامترshouldRemoveViewModelStoreمربوط به decorator را بهremoveViewModelStoreOnPopتغییر نام داده است تا مشخص شود که این فراخوانی فقط زمانی فراخوانی میشود که یک ورودی ازbackStackبرداشته شود. ( Iefdc5 , b/444447434 )
نسخه ۲.۱۰.۰-آلفا۰۴
۲۴ سپتامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha04 منتشر شد. نسخه 2.10.0-alpha04 شامل این کامیتها است.
تغییرات API
- تابع
LifecycleOwnerبهrememberLifecycleOwnerبازنویسی کنید. اکنون تابعLifecycleOwnerرا مستقیماً برمیگرداند. برای ارائه این مالک به یک sub-composition، ازCompositionLocalProviderاستفاده کنید. ( Ic57f0 ، b/444446629 ) - اضافه کردن Stub های KMP به lifecycle-viewmodel-navigation3 تا JetBrains بتواند fork هایی را ارائه دهد که این اهداف را پر می کنند و در نتیجه از CMP پشتیبانی می کنند. ( I44a4c )
نسخه ۲.۱۰.۰-alpha03
۲۷ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha03 منتشر شد. نسخه 2.10.0-alpha03 شامل این کامیتها است.
تغییرات API
- بهروزرسانی Compose به نسخه ۱.۹.۰ ( I2b9de )
نسخه ۲.۱۰.۰-alpha02
۱۳ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha02 منتشر شد. نسخه 2.10.0-alpha02 شامل این کامیتها است.
ویژگیهای جدید
کامپوننت
LifecycleOwnerاکنون میتواند یک چرخه حیات ریشه مستقل ایجاد کند. با تنظیم (صریح)parent = null، چرخه حیات جدید مستقل از هر میزبان (مانندActivity،FragmentیاNavBackStackEntry) عمل میکند. این چرخه به محض ورود کامپوننت به کامپوننت شروع میشود و هنگام خروج از آن به طور خودکار از بین میرود. ( I8dfbe ، b/433659048 )@Composable fun IndependentComponent() { // Create a standalone lifecycle, not tied to the parent Activity/Fragment. LifecycleOwner(parent = null) { val rootLifecycle = LocalLifecycleOwner.current.lifecycle } }
تغییرات API
- در کامپوننت
LifecycleOwner، پارامترparentLifecycleOwnerبهparentتغییر نام داده شده است ( I080bc ).
رفع اشکالات
- اکنون
LifecycleOwnercomposable به درستی چرخه حیات خود را پس از دفع بهDESTROYEDمنتقل میکند. این امر از نشت احتمالی کد خارجی که ارجاعی به چرخه حیات دارد، جلوگیری میکند. ( I9e5b7 ، b/433659048 ) - انتقال minSdk پیشفرض از API 21 به API 23 ( Ibdfca ، b/380448311 ، b/435705964 ، b/435705223 )
مشارکت خارجی
- فیلدهای پشتیبان داخلی غیرضروری را از
LifecycleOwnerحذف کنید. از جیک وارتون بابت مشارکتش متشکرم. ( Ideddb )
نسخه ۲.۱۰.۰-alpha01
۳۰ ژوئیه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha01 منتشر شد. نسخه 2.10.0-alpha01 شامل این کامیتها است.
ویژگیهای جدید
یک کامپوننت
LifecycleOwnerاضافه کنید تا امکان ایجاد چرخههای حیات محدود شده را مستقیماً در رابط کاربری فراهم کند. این برای کامپوننتهایی که نیاز به مدیریت مستقل چرخههای حیات خود دارند مفید است. برای مثالی از نحوه ادغام این کامپوننت جدید توسط Navigation3، به aosp/3708610 مراجعه کنید. ( 76cbf7 )@Composable fun MyComposable() { LifecycleOwner( maxLifecycle = RESUMED, parentLifecycleOwner = LocalLifecycleOwner.current, ) { val childLifecycleOwner = LocalLifecycleOwner.current } }
تغییرات API
- یک تابع سازندهی factory برای
CreationExtrasاضافه کنید که یک API کاتلین راحتتر و اصطلاحاًتر ارائه میدهد. ( Iab2bd ) - پشتیبانی بومی برای انواع تهیپذیر (nullable) در
SavedStateHandle.savedاضافه شده است که ذخیره و بازیابی ویژگیهای تهیپذیر را ساده میکند. ( I54d69 , b/421325690 ) - سازندههای
SavedStateHandleرا به صورت@VisibleForTestingعلامتگذاری کنید. ( Iff0e0 , b/408002794 )
نسخه ۲.۹
نسخه ۲.۹.۴
۱۷ سپتامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.4 منتشر شد. نسخه 2.9.4 شامل این کامیتها است.
رفع اشکالات
- خطایی که باعث میشد افزونه Compose Compiler اعمال نشود و باعث خرابی مصنوعات Lifecycle KMP شود، برطرف شد. ( Ie95bc ، b/443096483 ، b/443965665 )
نسخه ۲.۹.۳
۲۷ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.3 منتشر شد. نسخه 2.9.3 شامل این کامیتها است.
ویژگیهای جدید
- اضافه کردن اهداف جدید Kotlin Multiplatform (KMP) به مصنوعات Lifecycle
*-compose. Lifecycle اکنون در مجموع از پلتفرمهای زیر پشتیبانی میکند: JVM (اندروید و دسکتاپ)، Native (لینوکس، iOS، watchOS، macOS، MinGW) و وب (جاوااسکریپت، WasmJS). ( I0a0e4 )
رفع اشکالات
-
androidx.annotationبه نسخه ۱.۹.۱ بهروزرسانی کنید ( Ic9e4f ، b/397701294 )
نسخه ۲.۹.۲
۱۶ ژوئیه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.2 منتشر شد. نسخه 2.9.2 شامل این کامیتها است.
رفع اشکالات
- اهداف جدید Kotlin Multiplatform (KMP) به مصنوعات Lifecycle اضافه شد. Lifecycle اکنون در مجموع از پلتفرمهای زیر پشتیبانی میکند: JVM (اندروید و دسکتاپ)، Native (لینوکس، iOS، watchOS، macOS، MinGW) و وب (جاوااسکریپت، WasmJS). توجه داشته باشید که هیچ هدف KMP جدیدی به مصنوعات
*-composeاضافه نشده است، زیرا این امر به انتشار پایدار Compose 1.9 بستگی دارد. ( I01cb8 ).
بهروزرسانیهای وابستگی
- چرخه حیات اکنون برای فعال کردن پشتیبانی از اهداف جدید KMP ( Ic9e4f ، b/397701294 ) به Annotation
1.9.1وابسته است.
نسخه ۲.۹.۱
۴ ژوئن ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.1 منتشر شد. نسخه 2.9.1 شامل این کامیتها است.
رفع اشکالات
- رفع مشکل پاک نشدن وضعیتهای
SavedStateHandle.remove(key)SavedStateHandle.getMutableStateFlow(key). ( d5f939 , b/418746333 )
نسخه ۲.۹.۰
۷ مه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0 منتشر شد. نسخه 2.9.0 شامل این کامیتها است.
تغییرات مهم از زمان ۲.۸.۰
- یک مصنوع جدید
androidx.lifecycle:lifecycle-viewmodel-testingKMP در دسترس است که یک کلاسViewModelScenarioبرای آزمایشViewModelsبه صورت جداگانه ارائه میدهد، با پشتیبانی ازonClearedوSavedStateHandleو همچنین آزمایش مرگ و بازسازی فرآیند از طریقrecreate(). -
getMutableStateFlowبهSavedStateHandleاضافه کنید تا یکMutableStateFlowبرگرداند. این تابع جدید key-exclusive است و نمیتوان آن را باgetLiveDataاستفاده کرد. اگر سعی کنید از هر دو برای دسترسی به یک state استفاده کنید، یک استثنا ایجاد میشود. -
CreationExtrasاکنون شامل سربارگذاریهای عملگر شبیه به نقشه است تا امکان دستکاری اصطلاحی محتوا را در کاتلین فراهم کند. این امکان استفاده ازin،+=و+را باCreationExtrasفراهم میکند.
پشتیبانی از سریالسازی KotlinX
با پشتیبانی از سریالسازی KotlinX که در SavedState
1.3.0اضافه شده است، ماsaved، یک نماینده ویژگی lazy، را معرفی کردهایم تا ذخیره کلاسهای@Serializableدر یکSavedStateHandleآسان شود و این کلاسها به طور خودکار در طول مرگ و بازسازی فرآیند بازیابی شوند. لطفاً توجه داشته باشید که نمایندهsavedlazy است و تا زمانی که به آن دسترسی پیدا نشود، لامبداinitرا فراخوانی نمیکند یا چیزی را درSavedStateHandleذخیره نمیکند.@Serializable data class Person(val firstName: String, val lastName: String) class MyViewModel(handle: SavedStateHandle) : ViewModel() { var person by handle.saved { Person("John", "Doe") } fun onPersonChanged(person: Person) { this.person = person } }
کاتلین چندسکویی
- ماژول
lifecycle-testingاکنون با KMP از جمله APIهایی مانندTestLifecycleOwnerسازگار است. - ماژول
lifecycle-viewmodel-savedstateاکنون با KMP از جمله APIهایی مانندSavedStateHandleسازگار است. -
androidx.compose.ui.platform.LocalLifecycleOwnerاکنون در مجموعه منابع مشترک موجود است. -
NewInstanceFactoryاکنون در JVM Desktop و اندروید در دسترس است.
تغییرات رفتاری
- وضعیت
Lifecycle.DESTROYEDدر وضعیت پایانی قرار دارد و هرگونه تلاشی برای انتقال یکLifecycleاز آن به هر وضعیت دیگری، اکنون منجر به خطایIllegalStateExceptionخواهد شد. -
SavedStateHandleدیگر شامل هیچSavedStateProvider.saveState() نمیشود که در آنBundleبرگشتی خالی باشد.
نسخه ۲.۹.۰-rc01
۲۳ آوریل ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-rc01 منتشر شد. نسخه 2.9.0-rc01 شامل این کامیتها است.
هشدار سازگاری با API لینت
- JetBrains،
KaCallableMemberCallاز یک کلاس به یک رابط تغییر داد که سازگاری دودویی را از بین میبرد. اگر نسخه AGP پروژه شما با نسخهای که برای کامپایل بررسیهای lint استفاده میشود متفاوت باشد، این میتواند باعث خرابی شود. این بهروزرسانی در aosp/3577172 انجام شد اما در یادداشتهای انتشار وجود نداشت - ما در اینجا آن را توضیح میدهیم. راهحل پیشنهادی: بهروزرسانی به آخرین AGP پایدار. اگر نمیتوانید بهطور کامل بهروزرسانی کنید، ازandroid.experimental.lint.versionبرای تراز کردن بررسیهای lint با نسخه AGP خود استفاده کنید - برای جزئیات بیشتر به تغییرات رفتار Compose Runtime مراجعه کنید.
نسخه ۲.۹.۰-بتا۰۱
۹ آوریل ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-beta01 منتشر شد. نسخه 2.9.0-beta01 شامل این کامیتها است.
تغییرات API
-
Lifecycle ViewModel Composeاکنون از همان تنظیمات Kotlin Multiplatform مانند Compose Runtime 1.7.1 و بالاتر استفاده میکند - مصنوعات-desktopاکنون حذف شدهاند و مصنوعات-jvmStubsو-linuxx64Stubsاضافه شدهاند. هیچ یک از این اهداف برای استفاده در نظر گرفته نشدهاند، آنها متغیرهایی برای کمک به تلاشهای Jetbrains Compose هستند. ( I5cb14 , b/406592090 )
بهروزرسانیهای وابستگی
- این کتابخانه اکنون سطح زبان Kotlin 2.0 را هدف قرار میدهد و به KGP 2.0.0 یا جدیدتر نیاز دارد. ( Idb6b5 )
-
Lifecycle ViewModel Composeاکنون به Compose 1.7.8 وابسته است. ( I5cb14 ، b/406592090 )
نسخه ۲.۹.۰-آلفا۱۳
۲۶ مارس ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha13 بدون هیچ تغییر عمومی قابل توجهی منتشر شده است. نسخه 2.9.0-alpha13 شامل این کامیتها است.
نسخه ۲.۹.۰-آلفا۱۲
۱۲ مارس ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha12 منتشر شد. نسخه 2.9.0-alpha12 شامل این کامیتها است.
تغییرات API
- اضافه کردن حاشیهنویسی
@MainThreadبهViewModelProvider.getدر تمام پلتفرمهای KMP پشتیبانیشده. ( I7e8dd , b/397736115 ) - نام
SavedState*Delegatesرا بهSavedState*Delegateتغییر دهید. ( I8589b ، b/399629301 )
نسخه ۲.۹.۰-آلفا۱۱
۲۶ فوریه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha11 منتشر شد. نسخه 2.9.0-alpha11 شامل این کامیتها است.
تغییرات API
- پارامتر
SavedStateConfigرا به delegate هایsaved()اضافه کنید ( I39b3a )
نسخه ۲.۹.۰-آلفا۱۰
۱۲ فوریه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha10 منتشر شد. نسخه 2.9.0-alpha10 شامل این کامیتها است.
تغییرات API
-
MutableStateSerializerازlifecycle-viewmodel-composeبهsavedstate-composeمنتقل کنید. ( I4f690 ، b/378895074 )
مشارکت خارجی
- یک مشکل Lint جدید برای فراخوانی
Lifecycle::currentStateدر ترکیب اضافه میکند، به جای آن پیشنهاد میدهد ازcurrentStateAsalue().valueاستفاده شود تا اطمینان حاصل شود که تغییرات در وضعیت Lifecycle به درستی باعث ترکیب مجدد میشوند. با تشکر از استیون شوئن! ( Iad484 )
نسخه ۲.۹.۰-alpha09
۲۹ ژانویه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha09 منتشر شد. نسخه 2.9.0-alpha09 شامل این کامیتها است.
ویژگیهای جدید
- برای سریالسازی
androidx.compose.runtime.MutableStateMutableStateSerializerاضافه کنید. ( Idfc48 ، b/378895074 )
تغییرات API
- توابع نمایندهی
SavedStateHandle.saved()که سربارگذاری شدهاند را با پارامترهای پیشفرض ( Icd1c1 ) جایگزین کنید. -
AbstractSavedStateViewModelFactoryمنسوخ شده است زیرا برای هرViewModelیکSavedStateHandleایجاد میکند که باعث سربار غیرضروری میشود. برای ایجاد کارآمدترViewModel، به جای آن ازViewModelProvider.Factoryبه همراهCreationExtras.createSavedStateHandleاستفاده کنید. ( Ia920b , b/388590327 )
نسخه ۲.۹.۰-آلفا۰۸
۱۱ دسامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha08 منتشر شد. نسخه 2.9.0-alpha08 شامل این کامیتها است.
ویژگیهای جدید
-
ViewModelScenario.recreateرا برای شبیهسازی مرگ فرآیند سیستم کهViewModelتحت آزمایش و تمام اجزای مرتبط را دوباره ایجاد میکند، اضافه کنید. ( Id6a69 ، b/381063087 ) - نمونههای
LifecycleOwnerوViewModelStoreOwnerکه از طریق APIهایfindViewTreeمربوطه بازیابی میشوند، اکنون میتوانند از طریق والدهای مجزای یک نما، مانندViewOverlay، حل شوند. برای اطلاعات بیشتر در مورد والدهای مجزای نما، به یادداشتهای انتشار core یا مستندات موجود درViewTree.setViewTreeDisjointParentمراجعه کنید. ( I800f4 )
تغییرات API
- نامگذاریها و سازماندهی بستهها را با
SavedStateRegistryOwnerDelegate( I8c135 ، b/376026744 ) سازگارتر کنید.
رفع اشکالات
- این کتابخانه اکنون از حاشیهنویسیهای nullness از نوع JSpecify استفاده میکند که از نوع type-use هستند. توسعهدهندگان کاتلین باید از آرگومان کامپایلر زیر برای اعمال استفاده صحیح استفاده کنند:
-Xjspecify-annotations=strict(این پیشفرض است که از نسخه ۲.۱.۰ کامپایلر کاتلین شروع میشود). ( Ie4340 ، b/326456246 ) - توالی پاکسازی سند
ViewModel.onCleared. ( I586c7 ، b/363984116 )
نسخه ۲.۹.۰-آلفا۰۷
۱۳ نوامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha07 منتشر شد. نسخه 2.9.0-alpha07 شامل این کامیتها است.
سازگاری چند پلتفرمی کاتلین
- Lifecycle
ViewModel SavedStateاکنون با KMP سازگار است. این به شما امکان میدهد ازSavedStateHandleدر کد مشترک استفاده کنید. ( Ib6394 , b/334076622 )
پشتیبانی از سریالسازی KotlinX
با پشتیبانی از سریالسازی KotlinX که در SavedState
1.3.0-alpha05اضافه شده است،saved، یک نماینده ویژگی lazy، را معرفی کردهایم تا ذخیره کلاسهای@Serializableدر یکSavedStateHandleآسان شود و این کلاسها به طور خودکار در طول مرگ و بازسازی فرآیند بازیابی شوند. لطفاً توجه داشته باشید که نمایندهsavedlazy است و تا زمانی که به آن دسترسی پیدا نشود، لامبداinitرا فراخوانی نمیکند یا چیزی را درSavedStateHandleذخیره نمیکند. ( I47a88 , b/376026744 )@Serializable data class Person(val firstName: String, val lastName: String) class MyViewModel(handle: SavedStateHandle) : ViewModel() { var person by handle.saved { Person("John", "Doe") } fun onPersonChanged(person: Person) { this.person = person } }
تغییرات API
-
getMutableStateFlowبهSavedStateHandleاضافه کنید تا یکMutableStateFlowبرگرداند. این تابع جدید key-exclusive است و نمیتوان آن را باgetLiveDataاستفاده کرد. اگر سعی کنید از هر دو برای دسترسی به یک state استفاده کنید، یک استثنا ایجاد میشود. ( I04a4f , b/375408415 )
نسخه ۲.۹.۰-alpha06
۳۰ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha06 منتشر شد. نسخه 2.9.0-alpha06 شامل این کامیتها است.
تغییرات رفتاری
- وضعیت
Lifecycle.DESTROYEDدر وضعیت پایانی قرار دارد و هرگونه تلاشی برای انتقال یکLifecycleاز آن به هر وضعیت دیگری، منجر به خطایIllegalStateExceptionخواهد شد. ( I116c4 , b/370577987 ) -
SavedStateHandleدیگر شامل هیچSavedStateProvider.saveState() نمیشود که در آنBundleبرگشتی خالی باشد. ( I910b5 , b/370577987 )
رفع اشکالات
-
Lifecycle.eventFlowاکنون به درستی تکمیل میشود وقتیLifecycleDESTROYED( I293b2 ، b/374043130 )
نسخه ۲.۹.۰-آلفا۰۵
۱۶ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha05 بدون هیچ تغییر قابل توجهی منتشر شده است. نسخه 2.9.0-alpha05 شامل این کامیتها است.
نسخه ۲.۹.۰-آلفا۰۴
۲ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha04 منتشر شد. نسخه 2.9.0-alpha04 شامل این کامیتها است.
کاتلین چندسکویی
- ماژول
lifecycle-viewmodel-savedstateاکنون طوری پیکربندی شده است که با KMP سازگار باشد تا APIهایی مانندSavedStateHandleکه در نسخههای آینده در مجموعه منابع مشترک در دسترس قرار میگیرند، آماده شوند. ( I503ed ، I48764 ، b/334076622 )
نسخه ۲.۹.۰-آلفا۰۳
۱۸ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha03 منتشر شد. نسخه 2.9.0-alpha03 شامل این کامیتها است.
رفع اشکالات
- از Lifecycle
2.8.6: خطایNullSafeMutableLiveDataLint پشتیبانی از تبدیلهای هوشمند را بهبود بخشیده و از مثبتهای کاذب جلوگیری میکند. ( 85fed6 , b/181042665 )
بهروزرسانیهای وابستگی
- از چرخه حیات
2.8.6: چرخه حیات زمان اجرا Compose اکنون به Compose Runtime1.7.1بستگی دارد. - زمان اجرای چرخه عمر اکنون به ProfileInstaller
1.4.0بستگی دارد
نسخه ۲.۹.۰-آلفا۰۲
۴ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha02 منتشر شد. نسخه 2.9.0-alpha02 شامل این کامیتها است.
رفع اشکالات
- از Lifecycle
2.8.5: قوانینandroidx.lifecycle.ReportFragmentProGuard را بهروزرسانی کنید تا امکان مبهمسازی فراهم شود. ( ff898e1 )
مشارکت خارجی
-
androidx.compose.ui.platform.LocalLifecycleOwnerبه مجموعه منابع مشترک (KMP) منتقل کنید. با تشکر از ایوان ماتکوف از JetBrains برای کمک. ( 8cd5d03 ) - از Lifecycle
2.8.5: افزونهی SavedStateHandle.saveable` اکنون از مقادیر nullable پشتیبانی میکند. از رومن کالوکیویچ بابت مشارکتش متشکرم. ( 0d78ea6 )
نسخه ۲.۹.۰-آلفا۰۱
۷ آگوست ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha01 منتشر شد. نسخه 2.9.0-alpha01 شامل این کامیتها است.
کاتلین چندسکویی
-
lifecycle-testingاکنون با KMP سازگار است. ( Iea41e ) - پشتیبانی از هدف چند پلتفرمی
linuxArm64kotlin ( I139d3 ، b/338268719 ) اضافه شد.
ویژگیهای جدید
- یک مصنوع جدید
androidx.lifecycle:lifecycle-viewmodel-testingKMP در دسترس است که یک کلاسViewModelScenarioبرای آزمایش ViewModelها به صورت جداگانه ارائه میدهد، با پشتیبانی ازonCleared(همه پلتفرمها) وSavedStateHandle(فقط اندروید). ( 337f68d ، c9b3409 ، 9799a95c ، b/264602919 ) - ایجاد یک
ViewModelباViewModelProviderاکنون thread safe است؛ حاشیهنویسیهای@MainThreadحذف شدهاند. ( Ifd978 , b/237006831 )
تغییرات API
- تابع کارخانهای
CreationExtras.Key()برای سادهسازی ایجاد اشیاء بینامCreationExtras.Keyاضافه کنید. ( I970ee ) -
CreationExtrasاکنون شامل سربارگذاریهای عملگر شبیه به نقشه است تا امکان دستکاری اصطلاحی محتوا را در کاتلین فراهم کند. این امکان استفاده ازin،+=و+را باCreationExtrasفراهم میکند. ( Ib4353 ) -
CreationExtrasاکنون متدهایequals،hashCodeوtoStringرا پیادهسازی میکند. ( Ib4353 ) -
NewInstanceFactoryاکنون در JVM دسکتاپ و اندروید در دسترس است. ( d3d0892 ) - ویژگی افزونه درونخطی برای نمایش ایمن برنامهی اصلی در زبان کاتلین نسخهی ۲.۰ ( I39df2 )
رفع اشکالات
- حذف دستورالعمل دسترسی به APIهای پلتفرم جدید، زیرا این امر به طور خودکار از طریق مدلسازی API هنگام استفاده از R8 با AGP 7.3 یا بالاتر (مثلاً R8 نسخه 3.3) و برای همه نسخهها هنگام استفاده از AGP 8.1 یا بالاتر (مثلاً D8 نسخه 8.1) اتفاق میافتد. به مشتریانی که از AGP استفاده نمیکنند، توصیه میشود به D8 نسخه 8.1 یا بالاتر بهروزرسانی کنند. برای جزئیات بیشتر به این مقاله مراجعه کنید. ( If6b4c ، b/345472586 )
نسخه ۲.۸
نسخه ۲.۸.۷
۳۰ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.7 منتشر شد. نسخه 2.8.7 شامل این کامیتها است.
تغییرات API
-
androidx.compose.ui.platform.LocalLifecycleOwnerاکنون در مجموعه منابع مشترک (KMP) موجود است. ( 6a3f5b3 ) -
lifecycle-runtime-compose: مصنوعاتdesktopحذف شده و مصنوعات-jvmStubsو-linuxx64Stubsاضافه شدهاند. هیچ یک از این اهداف برای استفاده در نظر گرفته نشدهاند، آنها متغیرهایی برای کمک به تلاشهای Jetbrains Compose هستند. ( 6a3f5b3 )
نسخه ۲.۸.۶
۱۸ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.6 منتشر شد. نسخه 2.8.6 شامل این کامیتها است.
رفع اشکالات
- خطای
NullSafeMutableLiveDataLint پشتیبانی از تبدیلهای هوشمند را بهبود بخشیده و از مثبتهای کاذب جلوگیری میکند. ( 85fed6 , b/181042665 )
بهروزرسانیهای وابستگی
- چرخه عمر زمان اجرا Compose اکنون به Compose Runtime
1.7.1بستگی دارد.
نسخه ۲.۸.۵
۴ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.5 منتشر شد. نسخه 2.8.5 شامل این کامیتها است.
رفع اشکالات
- قوانین
androidx.lifecycle.ReportFragmentProGuard را بهروزرسانی کنید تا امکان مبهمسازی فراهم شود. ( ff898e1 )
مشارکت خارجی
- نماینده افزونه
SavedStateHandle.saveableاکنون از مقادیر nullable پشتیبانی میکند. از رومن کالوکیویچ برای مشارکتش متشکرم. ( 0d78ea6 )
نسخه ۲.۸.۴
۲۴ ژوئیه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.4 منتشر شد. نسخه 2.8.4 شامل این کامیتها است.
رفع اشکالات
-
LiveData.asFlow()اکنون به درستی مواردی را مدیریت میکند که Flow برگشتی بلافاصله پس از دریافت مقداری که از قبل درLiveDataتنظیم شده است، تکمیل میشود (برای مثال، هنگام استفاده ازtake(1)). ( I9c566 ) - تکمیل
Lifecycle*Effectاکنون خودتوان است (یعنی، اگرonStopOrDisposeبه دلیل توقف چرخه حیات فراخوانی شده باشد، پس از دفع، بار دوم فراخوانی نمیشود، مگر اینکه چرخه حیات دوباره به شروعSTARTED) برگردد). ( I5f607 ، b/352364595 )
نسخه ۲.۸.۳
۱ ژوئیه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.3 منتشر شد. نسخه 2.8.3 شامل این کامیتها است.
رفع اشکالات
- مشکل سازگاری معکوس Lifecycle 2.8 با Compose 1.6.0 و پایینتر هنگام استفاده از کاهش کد برطرف شد. ( aosp/3133056 , b/346808608 )
نسخه ۲.۸.۲
۱۲ ژوئن ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.2 منتشر شد. نسخه 2.8.2 شامل این کامیتها است.
رفع اشکالات
- رفع مشکل
CompositionLocal LocalLifecycleOwner not presentهنگام استفاده از Lifecycle 2.8.X با Compose 1.6.X یا نسخههای قدیمیتر - اکنون میتوانید از Lifecycle 2.8.2 با هر نسخهای از Compose بدون نیاز به هیچ راهکار جانبی استفاده کنید. ( aosp/3105647 , b/336842920 ) -
ViewModelProviderدیگر هنگام ترکیب نسخههای قبلی وابستگیهای چرخه عمرcompileOnlyبا نسخههای 2.8+ از کار نمیافتد و مشکلات مربوط به کتابخانههایی مانند LeakCanary ( I80383 ، b/341792251 ) برطرف میشود.
نسخه ۲.۸.۱
۲۹ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.1 منتشر شد. نسخه 2.8.1 شامل این کامیتها است.
رفع اشکالات
-
lifecycle-viewmodel-composeاکنون فقط یک وابستگی مشترک بهcompose-runtimeدارد و وابستگی مشترک آن بهcompose-uiحذف شده است. این محصول اندروید،compose-uiخود را برای سازگاری حفظ میکند. ( aosp/3079334 , b/339562627 ) - ادغام
saveableViewModelبا استفاده از نمایندههای ویژگی، اکنون از نام کلاس به عنوان بخشی از کلید تولید شده خودکار استفاده میکند و در صورت استفاده چندین کلاس از همانSavedStateHandle، از تداخل جلوگیری میکند. ( aosp/3063463 )
نسخه ۲.۸.۰
۱۴ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0 منتشر شد. نسخه 2.8.0 شامل این کامیتها است.
تغییرات مهم از زمان ۲.۷.۰
-
LocalLifecycleOwnerاز Compose UI بهlifecycle-runtime-composeمنتقل شده است تا APIهای کمکی مبتنی بر Compose آن بتوانند خارج از Compose UI نیز استفاده شوند. - آرتیفکت
lifecycle-runtime-composeاکنون شامل APIهایdropUnlessResumedوdropUnlessStartedاست که به شما امکان میدهند کلیک یا سایر رویدادهایی را که حتی پس از کاهشLifecycleOwnerبه زیرLifecycle.Stateداده شده رخ میدهند، حذف کنید. برای مثال، این میتواند با Navigation Compose برای جلوگیری از مدیریت رویدادهای کلیک پس از شروع انتقال به صفحه دیگر استفاده شود:onClick: () -> Unit = dropUnlessResumed { navController.navigate(NEW_SCREEN) } ViewModel.viewModelScopeاکنون یک پارامتر سازندهی قابل لغو است که به شما امکان میدهد dispatcher وSupervisorJob()خود را تزریق کنید یا با استفاده ازbackgroundScopeموجود درrunTestمقدار پیشفرض را لغو کنید. ( I2817c ، b/264598574 )class MyViewModel( // Make Dispatchers.Main the default, rather than Dispatchers.Main.immediate viewModelScope: CoroutineScope = Dispatchers.Main + SupervisorJob() ) : ViewModel(viewModelScope) { // Use viewModelScope as before, without any code changes } // Allows overriding the viewModelScope in a test fun Test() = runTest { val viewModel = MyViewModel(backgroundScope) }ViewModelدر کاتلین بازنویسی شده و اکنون به جایCloseableازAutoClosableاستفاده میکند. اکنون از افزودن اشیاءAutoCloseableباkeyکه امکان بازیابی آنها را از طریقgetCloseable()فراهم میکند، پشتیبانی میکند.فراخوانی
LifecycleStartEffectوLifecycleResumeEffectبدون کلید، اکنون یک خطا محسوب میشود و از همان قرارداد APIDisposableEffectکه این APIها از آن پیروی میکنند، پیروی میکند.LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)به نفعLiveData.toPublisher(lifecycleOwner)منسوخ شد.افزونههای کاتلین
lifecycle-livedata-core-ktxاکنون به ماژولlifecycle-livedata-coreمنتقل شدهاند.NullSafeMutableLiveDataبرای جلوگیری از بسیاری از تشخیصهای نادرست، بازسازی شده است.
سازگاری چند پلتفرمی کاتلین با چرخه حیات
APIهای اصلی چرخه حیات در Lifecycle ، LifecycleOwner ، LifecycleObserver ، Lifecycle.State ، Lifecycle.Event و LifecycleRegistry اکنون در مصنوعاتی سازگار با Kotlin Multiplatform ارائه میشوند.
مصنوعات آسیب دیده:
-
lifecycle-commonاکثر APIها را بهcommonمنتقل میکند و علاوه بر اندروید، از jvm و iOS نیز پشتیبانی میکند. -
lifecycle-runtimeاکثر APIها را بهcommonمنتقل میکند و علاوه بر اندروید، از jvm و iOS نیز پشتیبانی میکند. -
lifecycle-runtime-ktxاکنون خالی است و تمام APIها بهlifecycle-runtimeمنتقل شدهاند. -
lifecycle-runtime-composeتمام APIها را بهcommonمنتقل میکند و یک مصنوع اندروید ارسال میکند که با پشتیبانی چند پلتفرمیandroidx.composeمطابقت دارد.
سازگاری ViewModel با کاتلین در پلتفرمهای مختلف
مصنوع lifecycle-viewmodel و APIهایی مانند ViewModel ، ViewModelStore ، ViewModelStoreOwner و ViewModelProvider اکنون در مصنوعاتی سازگار با Kotlin Multiplatform ارائه میشوند.
برای تطبیق با این تغییر، متدهایی مانند متدهای ViewModelProvider که java.lang.Class<T> میگرفتند، اکنون متدی معادل دارند که kotlin.reflect.KClass<T> میگیرد.
سازگاری باینری در اندروید حفظ شده است، اما هنگام مقایسه سطح API اندروید با سطح API رایج، چند تغییر قابل توجه وجود دارد:
- ساخت یک نمونه
ViewModelProviderاکنون از طریق متدهایViewModelProvider.create()انجام میشود، نه اینکه مستقیماً سازنده آن را فراخوانی کنیم. -
ViewModelProvider.NewInstanceFactoryوViewModelProvider.AndroidViewModelFactoryفقط در اندروید در دسترس هستند.- توصیه میشود Factoryهای سفارشی از
ViewModelProvider.Factoryبسط داده شوند و از متدcreateکهCreationExtrasمیگیرد استفاده کنند یا ازviewModelFactoryKotlin DSL استفاده کنند.
- توصیه میشود Factoryهای سفارشی از
- استفاده از
ViewModelProviderبدون یک factory سفارشی در پلتفرمهای غیر JVM منجر به خطایUnsupportedOperationExceptionخواهد شد. در پلتفرمهای JVM، در صورت عدم ارائه factory سفارشی، سازگاری با استفاده از سازنده ViewModel با آرگومانهای no-args حفظ میشود. - در پلتفرمهایی که
Dispatchers.Mainدر دسترس نیست (مثلاً لینوکس)،viewModelScopeبه یکEmptyCoroutineContextجایگزین میشود.
مصنوعات آسیب دیده:
-
lifecycle-viewmodelاکثر APIها را بهcommonمنتقل میکند و علاوه بر اندروید، از jvm و iOS نیز پشتیبانی میکند. -
lifecycle-viewmodel-ktxاکنون خالی است و تمام APIها بهlifecycle-viewmodelمنتقل شدهاند. -
lifecycle-viewmodel-composeتمام APIها را بهcommonمنتقل میکند و یک مصنوع اندروید را ارسال میکند که با پشتیبانی چند پلتفرمیandroidx.composeمطابقت دارد.
تغییرات رفتاری
-
InitializerViewModelFactory(شامل تابع سازندهviewModelFactory) اکنون در صورتی که یکinitializerبا همانclazz: KClass<VM : ViewModel>قبلاً اضافه شده باشد،IllegalArgumentExceptionصادر میکند. ( Ic3a36 )
مشکلات شناخته شده
-
lifecycle-*:2.8.0حداقل به نسخه Compose 1.7.0-alpha05 ( b/336842920 ) نیاز دارد.
نسخه ۲.۸.۰-rc01
۱ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-rc01 منتشر شد. نسخه 2.8.0-rc01 شامل این کامیتها است.
رفع اشکالات
- مشکلی که باعث میشد Baseline Profile برای کلاسهای
lifecycle-commonبه درستی بستهبندی نشود، برطرف شد. این کلاسها اکنون درlifecycle-runtimeAAR بستهبندی شدهاند. ( aosp/3038274 , b/322382422 ) - تغییر ترتیب غیرعمدی در نحوه پاک شدن نمونههای
AutoCloseableمتصل به ViewModel برطرف شد - ترتیب قبلیaddCloseable(String, AutoCloseable)، سپسaddClosable(AutoCloseable)و در نهایتonCleared()بازیابی شده است. ( aosp/3041632 ) - بهبود رفتار پیشفرض ایجاد
viewModelScopeبرای محیطهای دسکتاپ بومی و JVM. ( aosp/3039221 )
مشارکت خارجی
- از ویکتور کروپ به خاطر بهبود بررسی thread اصلی در JVM Desktop متشکرم. ( aosp/3037116 )
نسخه ۲.۸.۰-بتا۰۱
۱۷ آوریل ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-beta01 منتشر شد. نسخه 2.8.0-beta01 شامل این کامیتها است.
ویژگیهای جدید
- مصنوع
lifecycle-runtime-composeاکنون با Kotlin Multiplatform سازگار است، کد آن بهcommonمنتقل شده و یک مصنوع اندروید ارائه میدهد که با پشتیبانی چند پلتفرمی برایandroidx.composeمطابقت دارد. ( If7a71 ، I4f4a0 ، b/331769623 )
نسخه ۲.۸.۰-آلفا۰۴
۳ آوریل ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha04 منتشر شد. نسخه 2.8.0-alpha04 شامل این کامیتها است.
ویژگیهای جدید
- مصنوع
lifecycle-viewmodel-composeاکنون با Kotlin Multiplatform سازگار است و کد آن بهcommonمنتقل شده و یک مصنوع اندروید ارائه میدهد که با پشتیبانی چند پلتفرمیandroidx.composeمطابقت دارد. برای تطبیق با این تغییر، متد ComposableviewModelاکنون علاوه برjava.lang.ClassیکKClassمیپذیرد. ( b/330323282 )
رفع اشکالات
-
NullSafeMutableLiveDataبرای جلوگیری از بسیاری از خطاهای مثبت (false positives) بازسازی شده است. ( I2d8c1 ، Iafb18 ، I03463 ، I7ecef )
بهروزرسانی وابستگی
- اکنون مصنوع
lifecycle-viewmodel-composeبه Compose 1.6.0 وابسته است. - چرخه حیات اکنون به Profile Installer 1.3.1 بستگی دارد.
نسخه ۲.۸.۰-alpha03
۲۰ مارس ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha03 منتشر شد. نسخه 2.8.0-alpha03 شامل این کامیتها است.
ویژگیهای جدید
ViewModel.viewModelScopeاکنون یک پارامتر سازندهی قابل لغو است که به شما امکان میدهد dispatcher وSupervisorJob()خود را تزریق کنید یا با استفاده ازbackgroundScopeموجود درrunTestمقدار پیشفرض را لغو کنید. ( I2817c ، b/264598574 )class MyViewModel( // Make Dispatchers.Main the default, rather than Dispatchers.Main.immediate viewModelScope: CoroutineScope = Dispatchers.Main + SupervisorJob() ) : ViewModel(viewModelScope) { // Use viewModelScope as before, without any code changes } // Allows overriding the viewModelScope in a test fun Test() = runTest { val viewModel = MyViewModel(backgroundScope) }
سازگاری چند پلتفرمی کاتلین
مصنوع lifecycle-viewmodel و APIهایی مانند ViewModel ، ViewModelStore ، ViewModelStoreOwner و ViewModelProvider اکنون در مصنوعاتی سازگار با Kotlin Multiplatform ارائه میشوند. ( b/214568825 )
برای تطبیق با این تغییر، متدهایی مانند متدهای ViewModelProvider که java.lang.Class<T> میگرفتند، اکنون متدی معادل دارند که kotlin.reflect.KClass<T> میگیرد.
سازگاری باینری در اندروید حفظ شده است، اما هنگام مقایسه سطح API اندروید با سطح API رایج، چند تغییر قابل توجه وجود دارد:
- ساخت یک نمونه
ViewModelProviderاکنون از طریق متدهایViewModelProvider.create()انجام میشود، نه اینکه مستقیماً سازنده آن را فراخوانی کنیم. -
ViewModelProvider.NewInstanceFactoryوViewModelProvider.AndroidViewModelFactoryفقط در اندروید در دسترس هستند.- توصیه میشود Factoryهای سفارشی از
ViewModelProvider.Factoryبسط داده شوند و از متدcreateکهCreationExtrasمیگیرد استفاده کنند یا ازviewModelFactoryKotlin DSL استفاده کنند.
- توصیه میشود Factoryهای سفارشی از
- استفاده از
ViewModelProviderبدون یک factory سفارشی در پلتفرمهای غیر JVM منجر به خطایUnsupportedOperationExceptionخواهد شد. در پلتفرمهای JVM، در صورت عدم ارائه factory سفارشی، سازگاری با استفاده از سازنده ViewModel با آرگومانهای no-args حفظ میشود. - در پلتفرمهایی که
Dispatchers.Mainدر دسترس نیست (مثلاً لینوکس)،viewModelScopeبه یکEmptyCoroutineContextجایگزین میشود.
تغییرات رفتاری
-
InitializerViewModelFactory(شامل تابع سازندهviewModelFactory) اکنون در صورتی که یکinitializerبا همانclazz: KClass<VM : ViewModel>قبلاً اضافه شده باشد،IllegalArgumentExceptionصادر میکند. ( Ic3a36 )
رفع اشکالات
-
ViewModel.getCloseableاکنون کلیدهای تکراری را مدیریت میکند: اگرkeyاز قبل یک منبعAutoCloseableمرتبط با خود داشته باشد، منبع قدیمی جایگزین شده و بلافاصله بسته میشود. ( Ibeb67 ) - دسترسی به
viewModelScopeیکViewModelاکنون به صورت thread safe است. ( If4766 , b/322407038 )
مشارکت خارجی
-
LocalLifecycleOwnerاز Compose UI به lifecycle-runtime-compose منتقل شد تا APIهای کمکی مبتنی بر Compose آن بتوانند خارج از Compose UI نیز استفاده شوند. از جیک وارتون بابت مشارکتش متشکرم. ( I6c41b , b/328263448 )
نسخه ۲.۸.۰-آلفا۰۲
۲۱ فوریه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha02 منتشر شد. نسخه 2.8.0-alpha02 شامل این کامیتها است.
ویژگیهای جدید
- APIهای
dropUnlessResumedوdropUnlessStartedاضافه شدهاند که به شما امکان میدهند کلیک یا سایر رویدادهایی را که حتی پس از کاهشLifecycleOwnerبه زیرLifecycle.Stateداده شده رخ میدهند، حذف کنید. برای مثال، این میتواند با Navigation Compose برای جلوگیری از مدیریت رویدادهای کلیک پس از شروع انتقال به صفحه دیگر استفاده شود:onClick: () -> Unit = dropUnlessResumed { navController.navigate(NEW_SCREEN) }( Icba83 , b/317230685 )
تبدیلهای کاتلین
-
ViewModelاکنون با زبان کاتلین نوشته شده است ( I16f26 ، b/214568825 ) - افزونههای کاتلین
lifecycle-viewmodel-ktxاکنون به ماژول پایه lifecycle منتقل شدهاند. ( Id787b ، b/274800183 ) - افزونههای کاتلین
lifecycle-runtime-ktxاکنون به ماژول پایه lifecycle منتقل شدهاند. ( Ic3686 ، b/274800183 ) - افزونههای کاتلین
lifecycle-livedata-core-ktxاکنون به ماژول پایه lifecycle منتقل شدهاند. ( I54a3d , b/274800183 )
سازگاری چند پلتفرمی کاتلین
- APIهای اصلی چرخه حیات در
Lifecycle،LifecycleOwner،LifecycleObserver،Lifecycle.State،Lifecycle.EventوLifecycleRegistryاکنون در مصنوعاتی سازگار با Kotlin Multiplatform ارائه میشوند. ( b/317249252 )
تغییرات API
- فراخوانی
LifecycleStartEffectوLifecycleResumeEffectبدون کلید اکنون یک خطا محسوب میشود و از همان قرارداد APIDisposableEffectکه این APIها از آن پیروی میکنند، پیروی میکند. ( Ib0e0c ، b/323518079 ) -
ViewModelاکنون به جایCloseableازAutoCloseableاستفاده میکند. این یک تغییر سازگار با نسخههای قبلی است. ( I27f8e , b/214568825 ) -
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)به نفعLiveData.toPublisher(lifecycleOwner)منسوخ شد. ( Iabe29 , b/262623005 )
مشارکت خارجی
- با تشکر از ایوان ماتکوف از Jetbrains برای کمک به انتقال Lifecycle به Kotlin Multiplatform ( aosp/2926690 ، I0c5ac ، If445d )
نسخه ۲.۸.۰-آلفا۰۱
۲۴ ژانویه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha01 منتشر شد. نسخه 2.8.0-alpha01 شامل این کامیتها است.
ویژگیهای جدید
-
ViewModelاکنون از اضافه کردن اشیاءCloseableباkeyکه امکان بازیابی آنها را از طریقgetCloseable()فراهم میکند، پشتیبانی میکند. ( I3cf63 )
نسخه ۲.۷
نسخه ۲.۷.۰
۱۰ ژانویه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.7.0 منتشر شد. نسخه 2.7.0 شامل این کامیتها است.
تغییرات مهم از زمان ۲.۶.۰
-
TestLifecycleOwnerاکنون شامل یک تابع تعلیقsetCurrentState()است که تضمین میکند تغییر حالت و تمام فراخوانیهایLifecycleObserverقبل از بازگشت تکمیل شدهاند. نکته قابل توجه این است که برخلاف تنظیم مستقیم ویژگیcurrentState، این ازrunBlockingاستفاده نمیکند و استفاده از آن را در یک کوروتین مانند آنچه توسطrunTestارائه میشود، ایمن میسازد. - The
LiveDataextensions ofmapandswitchMapnow mirror the behavior ofdistinctUntilChanged- if theLiveDatahas avalueset, themap/switchMapfunction will be immediately called to populate thevalueof the returnedLiveData. This ensures that the initial value will be set as part of the first composition (when used withobserveAsState()), but does not change the observation behavior - updates values from the sourceLiveDatawill still only apply once you start observing theLiveData. - This release fixes an issue where
SavedStateHandlewould not properly restore customParcelableclasses after process death and recreation. Due to type information that is lost by the Android framework, arrays of custom Parcelables require additional work (manually creating a typed array of the right type) and the documentation onget,getLiveData, andgetStateFlownow specifically calls this limitation out. - The proguard keep rules associated with
LifecycleObserverhave been removed. This means that proguarded code that wishes to use APIs via reflection (such as using the long since deprecated@OnLifecycleEventannotation) will need to provide their own keep rules for their specific use case.
Lifecycle Event Observability
- As an alternative to using a
LifecycleEventObserver, you can now observe aFlowofLifecycle.Eventvia theLifecycle.asFlow()extension method. - Jetpack Compose users can now use
LifecycleEventEffectto run Compose side effects based onLifecycle.Event.
@Composable
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
viewModel.refreshData()
}
// …
}
- Jetpack Compose users can use
LifecycleStartEffectandLifecycleResumeEffectto handle pairs of events - started to stopped and resumed to paused, respectively. This API mirrors the one found inDisposableEffectand is suitable for cases where the change being made when the state is going up needs to be reversed when going back down.
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleStartEffect(viewModel) {
val timeTracking = viewModel.startTrackingTimeOnScreen()
onStopOrDispose {
timeTracking.stopTrackingTimeOnScreen()
}
}
// …
}
See Run code on lifecycle events for more information.
Lifecycle State Observability
- The current
Lifecycle.Statecan now be observed via theLifecycle.currentStateFlowproperty, which returns aStateFlowwhere thevalueis the currentLifecycle.State. - Jetpack Compose users can use the
Lifecycle.currentStateAsState()extension to directly exposeLifecycle.Stateas ComposeState. This is equivalent (and a shorter alternative) tolifecycle.currentStateFlow.collectAsState().
See Collect lifecycle state with flows for more information.
Version 2.7.0-rc02
۱۳ دسامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-rc02 is released. Version 2.7.0-rc02 contains these commits.
رفع اشکالات
- Fixed an issue where
SavedStateHandlewould not properly restore customParcelableclasses after process death and recreation. Due to type information that is lost by the Android framework, arrays of custom Parcelables require additional work (manually creating a typed array of the right type) and the documentation onget,getLiveData, andgetStateFlownow specifically calls this limitation out. ( I0b55a )
Version 2.7.0-rc01
۱۵ نوامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-rc01 is released. Version 2.7.0-rc01 contains these commits.
رفع اشکالات
-
LifecycleStartEffectandLifecycleResumeEffectnow correctly dispose and recreate the effect block if theLifecycleOwneris changed. ( Ia25c6 )
Version 2.7.0-beta01
۱ نوامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-beta01 is released with no changes. Version 2.7.0-beta01 contains these commits.
- A beta version bump, no major changes to this release version.
Version 2.7.0-alpha03
۱۸ اکتبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha03 is released. Version 2.7.0-alpha03 contains these commits.
ویژگیهای جدید
-
lifecycle-runtime-testingnow contains a new Lint check to avoid setting theLifecycle.Stateof theTestLifecycleOwnerby using thecurrentStatefield when inside of a coroutine. The Lint check now suggests the suspendingsetCurrentStatewhich allows setting theLifecycle.Statewithout blocking. ( Icf728 , b/297880630 )
رفع اشکالات
- Fixed an issue with
LiveData.switchMapwhere returning the sameLiveDatainstance both on the initial call and a subsequent call would prevent theLiveDatainstance from being added as a source. ( Ibedcba7 )
Version 2.7.0-alpha02
۶ سپتامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha02 is released. Version 2.7.0-alpha02 contains these commits.
ویژگیهای جدید
-
TestLifecycleOwnernow includes the suspending functionsetCurrentState()to give users the option of usingTestLifecycleOwnerfrom within a coroutine such as one provided byrunTest. ( I329de , b/259344129 )
تغییرات API
- All files from the
lifecycle-livedata-ktxmodules have been moved into the mainlifecycle-livedatamodule. ( I10c6f , b/274800183 )
تغییرات رفتاری
- The
LiveData.map()andLiveData.switchMap()extensions now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it, ensuring that using the resulting LiveData in Jetpack Compose has the right state on the initial composition. ( I91d2b , b/269479952 ) -
ViewModel'saddCloseable()now immediately closes theCloseableif theViewModelhas already received a call toonCleared(). ( I4712e , b/280294730 )
رفع اشکالات
- From Lifecycle
2.6.2: Fixed an issue whereSavedStateHandlewould not correctly be restored after process death if the state was restored,save()was called without actually saving the state in the parentSavedStateRegistry, and then the state was restored again. This fixes the interaction betweenrememberSaveableand Navigation Compose'sNavHost. ( aosp/2729289 )
Version 2.7.0-alpha01
۲۶ ژوئیه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha01 is released. Version 2.7.0-alpha01 contains these commits.
تغییرات API
-
Lifecycle.Stateis now Compose-observable viaLifecycle.currentStateFlow, which returns aStateFlowwhere thevalueis the currentLifecycle.State. ( Ib212d , b/209684871 ) -
Lifecycle.Events can now able to be observed as aFlowwithLifecycle.asFlow().( If2c0f , b/176311030 ) -
LifecycleResumeEffectAPI has been added to run ComposeSideEffects based on bothLifecycle.Event.ON_RESUMEandLifecycle.Event.ON_PAUSEevent callbacks. ( I60386 , b/235529345 ) -
LifecycleStartEffectAPI has been added to run ComposeSideEffects based onLifecycle.Event.ON_STARTandLifecycle.Event.ON_STOPevent callbacks. ( I5a8d1 , b/235529345 ) -
LifecycleEventEffectAPI has been added to run ComposeSideEffects based onLifecycle.Event. ( Ic9794 , b/235529345 ) -
Lifecycle.collectAsState()extension has been added to directly exposeLifecycle.Stateas ComposeState. This is equivalent (and a shorter alternative) tolifecycle.currentStateFlow.collectAsState(). ( I11015 , b/235529345 )
رفع اشکالات
- The
LiveData.distinctUntilChanged()extension now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it. This does not change the observation behavior - updated values from the sourceLiveDatawill still only apply once you start observing theLiveDatareturned fromdistinctUntilChanged(). ( Ib482f ) - The proguard keep rules associated with
LifecycleObserverhave been removed. This means that proguarded code that wishes to use APIs via reflection will need to provide their own keep rules for their specific use case. ( Ia12fd )
نسخه ۲.۶
نسخه ۲.۶.۲
۶ سپتامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.2 is released. Version 2.6.2 contains these commits.
رفع اشکالات
- Fixed an issue where
SavedStateHandlewould not correctly be restored after process death if the state was restored,save()was called without actually saving the state in the parentSavedStateRegistry, and then the state was restored again. This fixes the interaction betweenrememberSaveableand Navigation Compose'sNavHost. ( aosp/2729289 )
Version 2.6.1
۲۲ مارس ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.1 is released. Version 2.6.1 contains these commits.
بهروزرسانیهای وابستگی
-
lifecycle-viewmodel-savedstatenow depends on SavedState1.2.1. ( cd7251 ) - Lifecycle now depends on ProfileInstaller
1.3.0. ( f9d30b )
نسخه ۲.۶.۰
۸ مارس ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0 is released. Version 2.6.0 contains these commits.
Important changes since 2.5.0
-
LiveDatanow includes a newisInitializedproperty that indicates whether an explicit value has ever been set on theLiveData, allowing you to distinguish betweenliveData.valuereturningnullbecause no value has ever been set or an explicitnullvalue. -
MediatorLiveDatanow includes a constructor to set an initial value. - Added a new extension on
StateFlowandFlowofcollectAsStateWithLifecycle()that collect from flows and represents its latest value as Compose State in a lifecycle-aware manner. -
Lifecycle.launchWhenXmethods andLifecycle.whenXmethods have been deprecated as the use of a pausing dispatcher can lead to wasted resources in some cases. It is recommended to useLifecycle.repeatOnLifecycle. For more information about one-time suspending work, please see this explanation on why this is inherently unsafe. - Kotlin Conversion - A large number of Lifecycle classes have been converted to Kotlin. All converted classes still retain their binary compatibility with previous versions. The following classes have source incompatible changes for classes written in Kotlin:
ViewTreeLifecycleOwner,LiveDataReactiveStreams,HasDefaultViewModelProviderFactory,ViewTreeViewModelStoreOwner,Transformations,ViewModelStoreOwner,LifecycleOwner
The table below provides the source conversions for the new version of lifecycle.
| Lifecycle 2.5 | Lifecycle 2.5 (KTX) | Lifecycle 2.6 |
|---|---|---|
Transformations.switchMap(liveData) {...} | liveData.switchMap {...} | liveData.switchMap {...} |
Transformations.map(liveData) {...} | liveData.map {...} | liveData.map {...} |
Transformations.distinctUntilChanged(liveData) {...} | liveData.distinctUntilChanged{...} | liveData.distinctUntilChanged{...} |
LiveDataReactiveStreams.fromPublisher(publisher) | publisher.toLiveData() | publisher.toLiveData() |
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData) | liveData.toPublisher(lifecycleOwner) | liveData.toPublisher(lifecycleOwner) |
override fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory = factory | override fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory = factory | override val defaultViewModelProviderFactory = factory |
override fun getDefaultViewModelCreationExtras(): CreationExtras = extras | override fun getDefaultViewModelCreationExtras(): CreationExtras = extras | override val defaultViewModelProviderCreationExtras = extras |
ViewTreeLifecycleOwner.set(view, owner) | ViewTreeLifecycleOwner.set(view, owner) | view.setViewTreeLifecycleOwner(owner) |
ViewTreeLifecycleOwner.get(view) | view.findViewTreeLifecycleOwner() | view.findViewTreeLifecycleOwner() |
override fun getViewModelStore(): ViewModelStore = store | override fun getViewModelStore(): ViewModelStore = store | override val viewModelStore: ViewModelStore = store |
override fun getLifecycle(): Lifecycle = registry | override fun getLifecycle(): Lifecycle = registry | override val lifecycle: Lifecycle get() = registry |
- The nullability of the
onChangedmethod of aObservercreated in Kotlin now matches the nullability of the generic type. If you wantObserver.onChanged()to accept a nullable type, you must instantiate theObserverwith a nullable type. - These classes were also converted to Kotlin, but remain source compatible:
DefaultLifecycleObserver,LifecycleEventObserver,Lifecycle,LifecycleRegistry,LifecycleObserver,ViewModelStore,AndroidViewModel,AbstractSavedStateViewModelFactory,LifecycleService,ServiceLifecycleDispatcher, andProcessLifecycleOwner
Version 2.6.0-rc01
۲۲ فوریه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-rc01 is released. Version 2.6.0-rc01 contains these commits.
رفع اشکالات
- The
LiveData.distinctUntilChanged()extension now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it. This does not change the observation behavior - updated values from the sourceLiveDatawill still only apply once you start observing theLiveDatareturned fromdistinctUntilChanged(). ( Ib482f )
Version 2.6.0-beta01
۸ فوریه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-beta01 is released. Version 2.6.0-beta01 contains these commits.
تبدیلهای کاتلین
-
LifecycleOwneris now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thelifecycleproperty rather than implementing the previousgetLifecycle()function. ( I75b4b , b/240298691 ) -
ViewModelStoreOwneris now in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override theviewModelStoreproperty rather than implementing the previousgetViewModelStore()function. ( I86409 , b/240298691 ) - The Kotlin extension on
LifecycleOwnerthat provides thelifecycleScopefield has been moved to thelifecycle-commonartifact fromlifecycle-runtime-ktx. ( I41d78 , b/240298691 ) - The Kotlin extension on
Lifecyclethat provides thecoroutineScopefield has been moved to thelifecycle-commonartifact fromlifecycle-runtime-ktx. ( Iabb91 , b/240298691 )
Version 2.6.0-alpha05
۲۵ ژانویه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-alpha05 is released. Version 2.6.0-alpha05 contains these commits.
تبدیلهای کاتلین
-
Transformationsis now written in Kotlin. This is a source incompatible change for those classes written in Kotlin that were directly using syntax such asTransformations.map- Kotlin code must now use the Kotlin extension method syntax that was previously only available when usinglifecycle-livedata-ktx. When using the Java programming language, the versions of these methods that take anandroidx.arch.core.util.Functionmethod are deprecated and replaced with the versions that take a KotlinFunction1. This change maintains binary compatibility. ( I8e14f ) -
ViewTreeViewModelStoreOwneris now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.lifecycle.setViewTreeViewModelStoreOwnerandandroidx.lifecycle.findViewTreeViewModelStoreOwnerto set and find a previously set owner. This is binary compatible and remains source compatible for implementations written in the Java programming language. ( Ia06d8 , Ib22d8 , b/240298691 ) - The
HasDefaultViewModelProviderFactoryinterface is now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thedefaultViewModelProviderFactoryanddefaultViewModelCreationExtrasproperties rather than implementing the previous corresponding functions. ( Iaed9c , b/240298691 ) -
Observeris now written in Kotlin. ItsonChanged()method now uses the namevaluefor its parameter. ( Iffef2 , I4995e , b/240298691 ) -
AndroidViewModel,AbstractSavedStateViewModelFactory,LifecycleService,ServiceLifecycleDispatcher, andProcessLifecycleOwnerare now written in Kotlin ( I2e771 , Ibae40 , I160d7 , I08884 , I1cda7 , b/240298691 )
Version 2.6.0-alpha04
۱۱ ژانویه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-alpha04 is released. Version 2.6.0-alpha04 contains these commits.
ویژگیهای جدید
-
LiveDatanow includes a newisInitializedproperty that indicates whether an explicit value has ever been set on theLiveData, allowing you to distinguish betweenliveData.valuereturningnullbecause no value has ever been set or an explicitnullvalue. ( Ibd018 )
تغییرات API
- The
collectAsStateWithLifecycle()APIs oflifecycle-runtime-composeare no longer in experimental status. ( I09d42 , b/258835424 ) -
Lifecycle.launchWhenXmethods andLifecycle.whenXmethods have been deprecated as the use of a pausing dispatcher can lead to wasted resources in some cases. It is recommended to useLifecycle.repeatOnLifecycle. ( Iafc54 , b/248302832 )
تبدیلهای کاتلین
-
ViewTreeLifecycleOwneris now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.lifecycle.setViewTreeLifecycleOwnerandandroidx.lifecycle.findViewTreeLifecycleOwnerto set and find a previously set owner. This replaces the previous Kotlin extension inlifecycle-runtime-ktx. This is binary compatible and remains source compatible for implementations written in the Java programming language. ( I8a77a , I5234e , b/240298691 ) -
LiveDataReactiveStreamsis now written in Kotlin. The Kotlin extensions previously inlifecycle-reactivestreams-ktxhave been moved into thelifecycle-reactivestreamsmodule and have become the primary surface for code written in Kotlin. This is a source incompatible change for code written in Kotlin if you were not already using the Kotlin extension method APIs. ( I2b1b9 , I95d22 , b/240298691 ) -
DefaultLifecycleObserver,LifecycleEventObserver,Lifecycle,LifecycleRegistry,LifecycleObserver, andViewModelStoreare now written in Kotlin ( Iadffd , ( I60034 , I8c52c , I9593d , I01fe1 , I59a23 , b/240298691 )
رفع اشکالات
-
SavedStateHandleno longer crashes with aClassCastExceptionwhen callingget()with the incorrect class type. ( I6ae7c )
Version 2.6.0-alpha03
۲۴ اکتبر ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha03 is released. Version 2.6.0-alpha03 contains these commits.
رفع اشکالات
- Fixed an issue with constraints between different Lifecycle modules not working as intended. ( I18d0d , b/249686765 )
- Errors thrown by
LifecycleRegistry.moveToState()now include a more helpful error messaging that informs developers of the component causing the error. ( Idf4b2 , b/244910446 )
Version 2.6.0-alpha02
۷ سپتامبر ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha02 is released. Version 2.6.0-alpha02 contains these commits.
تغییرات API
-
MediatorLiveDatanow includes a constructor to set an initial value. ( Ib6cc5 , b/151244085 )
رفع اشکالات
-
Lifecycleartifacts now include constraints that ensure that all inter-dependent Lifecycle artifacts use the same version, automatically upgrading other dependencies when one is upgraded. b/242871265 -
FlowLiveData.asFlow()now creates acallbackFlowrather than using its ownChannelimplementation to ensure thread-safety and context preservation. ( I4a8b2 , b/200596935 ) -
FlowLiveData'sasLiveDatafunction will now preserve the initial value of aStateFlowwhen creating the newLiveDataobject. ( I3f530 , b/157380488 ) - From Lifecycle
2.5.1: Custom implementations ofAndroidViewModelFactorynow correctly calls thecreate(modelClass)function when using the stateful constructor withLifecycle2.4+ ( I5b315 , b/238011621 )
Version 2.6.0-alpha01
۲۹ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha01 is released. Version 2.6.0-alpha01 contains these commits.
ویژگیهای جدید
- Added a new extension on
StateFlowandFlowofcollectAsStateWithLifecyclethat collect from flows and represents its latest value as Compose State in a lifecycle-aware manner. The flow is collected and the new emission is set to the State's value when the lifecycle is at least in a certainLifecycle.State. When the lifecycle falls below thatLifecycle.State, the flow collection stops and the State's value is not updated. ( I1856e , b/230557927 )
نسخه ۲.۵
نسخه ۲.۵.۱
۲۷ ژوئیه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.1 is released. Version 2.5.1 contains these commits.
رفع اشکالات
- Custom implementations of
AndroidViewModelFactorynow correctly call thecreate(modelClass)function when using the statefulAndroidViewModelFactoryconstructor withLifecycle2.4+. ( I5b315 , b/238011621 )
Version 2.5.0
۲۹ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0 is released. Version 2.5.0 contains these commits.
Important changes since 2.4.0
SavedStateHandlenow offers agetStateFlow()API that returns a KotlinStateFlowfor monitoring value changes as an alternative to usingLiveData.ViewModel CreationExtras - when writing a custom
ViewModelProvider.Factory, it is no longer required to extendAndroidViewModelFactoryorAbstractSavedStateViewModelFactoryto gain access to anApplicationorSavedStateHandle, respectively. Instead, these fields are provided to everyViewModelProvider.Factorysubclass asCreationExtrasvia the new overload ofcreate:create(Class<T>, CreationExtras). These extras are provided automatically by your Activity or Fragment when using Activity1.5.0and Fragment1.5.0, respectively.class CustomFactory : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T { return when (modelClass) { HomeViewModel::class -> { // Get the Application object from extras val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) // Pass it directly to HomeViewModel HomeViewModel(application) } DetailViewModel::class -> { // Create a SavedStateHandle for this ViewModel from extras val savedStateHandle = extras.createSavedStateHandle() DetailViewModel(savedStateHandle) } else -> throw IllegalArgumentException("Unknown class $modelClass") } as T } }lifecycle-viewmodelnow provides aviewModelFactoryKotlin DSL that allows you define yourViewModelProvider.Factoryin terms of one or more lambda initializers, one for each particularViewModelclass your custom factory supports, usingCreationExtrasas the primary data source.val customFactory = viewModelFactory { // The return type of the lambda automatically sets what class this lambda handles initializer { // Get the Application object from extras provided to the lambda val application = checkNotNull(get(ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY)) HomeViewModel(application) } initializer { val savedStateHandle = createSavedStateHandle() DetailViewModel(savedStateHandle) } }lifecycle-viewmodel-composenow offers aviewModel()API that takes a lambda factory for creating aViewModelinstance without requiring the creation of a customViewModelProvider.Factory.// Within a @Composable, you can now skip writing a custom Factory // and instead write a lambda to do the initialization of your ViewModel val detailViewModel = viewModel { // This lambda is only called the first time the ViewModel is created // and all CreationExtras are available inside the lambda val savedStateHandle = createSavedStateHandle() DetailViewModel(savedStateHandle) }SavedStateHandle Compose Saver Integration - the
lifecycle-viewmodel-composeartifact now contains new experimental APIs inSavedStateHandle.saveablethat allowrememberSaveablelike behavior backed by theSavedStateHandleof a `ViewModel.class ListScreenViewModel(handle: SavedStateHandle): ViewModel() { // This value survives both configuration changes and process death and recreation val editMode by handle.saveable { mutableStateOf(false) } }Added an
addCloseable()API and a new constructor overload that allow you to add one or moreCloseableobjects to theViewModelthat will be closed when theViewModelis cleared without requiring any manual work inonCleared().For instance, to create a coroutine scope that you can inject into a ViewModel, but control via testing, you can create a
CoroutineScopethat implementsCloseable:class CloseableCoroutineScope( context: CoroutineContext = SupervisorJob() + Dispatchers.Main.immediate ) : Closeable, CoroutineScope { override val coroutineContext: CoroutineContext = context override fun close() { coroutineContext.cancel() } }Which can then be used in your
ViewModelconstructor while maintaining the same lifetime asviewModelScope:class TestScopeViewModel( val customScope: CloseableCoroutineScope = CloseableCoroutineScope() ) : ViewModel(customScope) { // You can now use customScope in the same way as viewModelScope }
Behavior changes
- Attempting to move the
Lifecycle.StatefromINITIALIZEDtoDESTROYEDwill now always throw anIllegalStateExceptionregardless of whether theLifecyclehas an attached observer. -
LifecycleRegistrywill now clear their observers when they reach theDESTROYEDstate.
Version 2.5.0-rc02
۱۵ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-rc02 is released. Version 2.5.0-rc02 contains these commits.
رفع اشکالات
-
ViewModelProviderwill no longer crash when mixing previous versions of compileOnly Lifecycle dependencies with versions 2.5+. ( I81a66 , b/230454566 )
Version 2.5.0-rc01
۱۱ مه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-rc01 is released. Version 2.5.0-rc01 contains these commits.
رفع اشکالات
-
MediatorLiveData.addSource()now throws aNullPointerExceptionwhen passed anullsource instead of propagating thenullsource to observers.( Ibd0fb , b/123085232 )
Version 2.5.0-beta01
۲۰ آوریل ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-beta01 is released. Version 2.5.0-beta01 contains these commits.
تغییرات API
- Added
SavedStateHandle.saveableproperty delegates to use property names as keys for persisting state into theSavedStateHandle( I8bb86 , b/225014345 )
رفع اشکالات
- Fixed an issue where nesting one
NavHostwithin anotherNavHostin a non-primary bottom navigation tab would lead to anIllegalStateExceptionwhen using multiple back stacks. ( I11bd5 , b/228865698 )
Version 2.5.0-alpha06
۶ آوریل ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha06 is released. Version 2.5.0-alpha06 contains these commits.
ویژگیهای جدید
- Add experimental
MutableStateoverload toSavedStateHandle.saveablefor parity withrememberSaveable( I38cfe , b/224565154 )
تغییرات API
-
CreationExtrasis now abstract instead of sealed. ( Ib8a7a )
رفع اشکالات
- Fixed an
IllegalStateException: Already attached to lifecycleOwnererror caused bySavedStateHandleController. ( I7ea47 , b/215406268 )
Version 2.5.0-alpha05
۲۳ مارس ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha05 is released. Version 2.5.0-alpha05 contains these commits.
ویژگیهای جدید
- The
lifecycle-viewmodel-composemodule now providesSavedStateHandleSaver, an experimental API that ensures values in aSavedStateHandleare integrated correctly with the same saved instance state thatrememberSaveableuses. ( Ia88b7 , b/195689777 )
تغییرات API
- Fixed a compatibility issue with Lifecycle 2.3 and newer Lifecycle versions in Java. ( I52c8a , b/219545060 )
رفع اشکالات
-
SavedStateViewFactorynow supports usingCreationExtraseven when it was initialized with aSavedStateRegistryOwner. If extras are provided, the initialized arguments are ignored. ( I6c43b , b/224844583 )
Version 2.5.0-alpha04
۹ مارس ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha04 is released. Version 2.5.0-alpha04 contains these commits.
تغییرات API
-
SavedStateHandlenow offers agetStateFlow()API that returns a KotlinStateFlowfor monitoring value changes as an alternative to usingLiveData. ( Iad3ab , b/178037961 )
Version 2.5.0-alpha03
۲۳ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha03 is released. Version 2.5.0-alpha03 contains these commits.
ویژگیهای جدید
- Added an
addCloseable()API and a new constructor overload that allow you to add one or moreCloseableobjects to theViewModelthat will be closed when theViewModelis cleared without requiring any manual work inonCleared(). ( I55ea0 ) -
lifecycle-viewmodelnow provides anInitializerViewModelFactorythat allows you to add lambda for handling particularViewModelclasses, usingCreationExtrasas the primary data source. ( If58fc , b/216687549 ) -
lifecycle-viewmodel-composenow offers aviewModel()API that takes a lambda factory for creating aViewModelinstance without requiring the creation of a customViewModelProvider.Factory. ( I97fbb , b/216688927 )
تغییرات API
- You can now create a
ViewModelwithCreationExtrasvialifecycle-viewmodel-compose. ( I08887 , b/216688927 )
Behavior changes
- Attempting to move the
Lifecycle.StatefromINITIALIZEDtoDESTROYEDwill now always throw anIllegalStateExceptionregardless of whether theLifecyclehas an attached observer. ( I7c390 , b/177924329 ) -
LifecycleRegistrywill now clear their observers when they reach theDESTROYEDstate. ( I4f8dd , b/142925860 )
Version 2.5.0-alpha02
۹ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha02 is released. Version 2.5.0-alpha02 contains these commits.
تغییرات API
-
SavedStateHandleandSavedStateViewModelFactoryhave been converted to Kotlin. This has improved the nullability of the generics in both classes. ( Ib6ce2 , b/216168263 , I9647a , b/177667711 ) - The
LiveDataswitchMapfunction parameter can now have a nullable output. ( I40396 , b/132923666 ) - The
LiveData-ktx extensions are now annotated with@CheckResultto enforce that the result is used when calling these functions. ( Ia0f05 , b/207325134 )
Behavior changes
-
SavedStateHandlenow properly stores the defaultValue when no value for the specified key exists. ( I1c6ce , b/178510877 )
رفع اشکالات
- From Lifecycle
2.4.1: Updatedlifecycle-processto depend on Startup 1.1.1 to ensure that fixes that preventProcessLifecycleInitializerfrom throwing aStartupExceptionare available by default. ( Ib01df , b/216490724 ) - There is now an improved error message when custom
AndroidViewModelclasses have parameters in the wrong order and attempt to create aViewModel. ( I340f7 , b/177667711 ) - You can now create a view model via
CreationExtrasusing theAndroidViewModelFactorywithout setting an application. ( I6ebef , b/217271656 )
Version 2.5.0-alpha01
January 26, 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha01 is released. Version 2.5.0-alpha01 contains these commits.
ViewModel CreationExtras
With this release, we are laying the groundwork for restructuring how a ViewModel is constructed. Instead of a rigid set of subclasses of ViewModelProvider.Factory that each add additional functionality (allowing an Application constructor parameter via AndroidViewModelFactory , allowing a SavedStateHandle constructor parameter via SavedStateViewModelFactory and AbstractSavedStateViewModelFactory , etc.), we are moving to a world of stateless factories that rely on a new concept, CreationExtras . ( Ia7343 , b/188691010 , b/188541057 )
With this change, ViewModelProvider no longer makes direct calls into the previous create(Class<T>) method of ViewModelProvider.Factory . Instead, it calls into a new overload of create : create(Class<T>, CreationExtras) . This means that any direct implementation of the ViewModelProvider.Factory instance now has access to each of these new CreationExtras :
-
ViewModelProvider.NewInstanceFactory.VIEW_MODEL_KEY: thisStringprovides access to the custom key you passed toViewModelProvider.get(). -
ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYprovides access to theApplicationclass. -
SavedStateHandleSupport.SAVED_STATE_REGISTRY_OWNER_KEYprovides access to theSavedStateRegistryOwnerthat is being used to construct this ViewModel. -
SavedStateHandleSupport.VIEW_MODEL_STORE_OWNER_KEYprovides access to theViewModelStoreOwnerthat is being used to construct this ViewModel. -
SavedStateHandleSupport.DEFAULT_ARGS_KEYprovides access to theBundleof arguments that should be used to construct aSavedStateHandle.
These extras are provided by default when using Activity 1.5.0-alpha01 , Fragment 1.5.0-alpha01 , and Navigation 2.5.0-alpha01 . If you use an earlier version of those libraries, your CreationExtras will be empty - all of the existing subclasses of ViewModelProvider.Factory have been rewritten to support both the legacy creation path used by earlier versions of those libraries and the CreationExtras path which will be used going forward.
These CreationExtras allow you to construct a ViewModelProvider.Factory that passes just the information you need to each ViewModel without relying on a strict hierarchy of Factory subclasses:
class CustomFactory : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
return when (modelClass) {
HomeViewModel::class -> {
// Get the Application object from extras
val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY])
// Pass it directly to HomeViewModel
HomeViewModel(application)
}
DetailViewModel::class -> {
// Create a SavedStateHandle for this ViewModel from extras
val savedStateHandle = extras.createSavedStateHandle()
DetailViewModel(savedStateHandle)
}
else -> throw IllegalArgumentException("Unknown class $modelClass")
} as T
}
}
We use the createSavedStateHandle() Kotlin extension function on CreationExtras from SavedStateHandleSupport to construct a SavedStateHandle only for the one ViewModel that needs it. ( Ia6654 , b/188541057 )
Custom CreationExtras can be provided by overriding getDefaultViewModelCreationExtras() in your ComponentActivity or Fragment , thus making them available to your custom ViewModelProvider.Factory as a built in form of assisted injection. These extras will automatically be made available to your custom Factory when used directly with ViewModelProvider or when using the by viewModels() and by activityViewModels() Kotlin property extensions. ( I79f2b , b/207012584 , b/207012585 , b/207012490 )
رفع اشکالات
- Fixed an issue where the default value provided to a
SavedStateHandlewould reappear after process death and recreation, even if it was specifically removed from theSavedStateHandle. As a consequence of this,SavedStateHandlewill no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b )
نسخه ۲.۴
نسخه ۲.۴.۱
۹ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.4.1 is released. Version 2.4.1 contains these commits.
رفع اشکالات
- Backported from Lifecycle
2.5.0-alpha01: Fixed an issue where the default value provided to aSavedStateHandlewould re-appear after process death and recreation, even if it was specifically removed from theSavedStateHandle. As a consequence of this,SavedStateHandlewill no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b ) -
lifecycle-processnow depends on Androidx Startup 1.1.1 which fixed a regression in where usingProcessLifecycleInitializerwould cause anStartupException. ( b/216490724 )
نسخه ۲.۴.۰
۲۷ اکتبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0 is released. Version 2.4.0 contains these commits.
Important changes since 2.3.0
-
@OnLifecycleEventwas deprecated.LifecycleEventObserverorDefaultLifecycleObservershould be used instead. -
androidx.lifecycle:lifecycle-viewmodel-composelibrary was added. It providesviewModel()composable andLocalViewModelStoreOwner.- Source-breaking change :
ViewModelProviderhas been rewritten in Kotlin.ViewModelProvider.Factory.createmethod no longer allows nullable generic.
- Source-breaking change :
- New coroutines API were added to
androidx.lifecycle:lifecycle-runtime-ktx: -
Lifecycle.repeatOnLifecycle, API that executes a block of code in a coroutine when the Lifecycle is at least in a certain state. The block will cancel and re-launch as the lifecycle moves in and out of the target state; -
Flow.flowWithLifecycle, API that emits values from the upstream Flow when the lifecycle is at least in a certain state. -
DefaultLifecycleObserverwas moved fromlifecycle.lifecycle-common-java8tolifecycle.lifecycle-common.lifecycle.lifecycle-common-java8doesn't provide anymore any additional functionality on top oflifecycle.lifecycle-common, so dependency on it can be replaced bylifecycle.lifecycle-common. - Non coroutines API from
lifecycle-viewmodel-ktxhave been moved to thelifecycle-viewmodelmodule. lifecycle-processnow usesandroidx.startupto initialize theProcessLifecycleOwner.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer.If you used
tools:node="remove"theContentProviderbeing used to initialize process lifecycle in the past, then you need to do the following instead.<provider android:name="androidx.startup.InitializationProvider" android:authorities=\"${applicationId}.androidx-startup" android:exported="false" tools:node=\"merge"> <!-- If you are using androidx.startup to initialize other components --> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" tools:node="remove" /> </provider>(یا)
<!-- If you want to disable androidx.startup completely. --> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="remove"> </provider>
Version 2.4.0-rc01
۲۹ سپتامبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-rc01 is released with no changes from Lifecycle 2.4.0-beta01. Version 2.4.0-rc01 contains these commits.
Version 2.4.0-beta01
۱۵ سپتامبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-beta01 is released. Version 2.4.0-beta01 contains these commits.
تغییرات API
-
@OnLifecycleEventwas deprecated.LifecycleEventObserverorDefaultLifecycleObservershould be used instead. ( I5a8fa ) - DefaultLifecycleObserver was moved from
androidx.lifecycle.lifecycle-common-java8toandroidx.lifecycle.lifecycle-common.androidx.lifecycle.lifecycle-common-java8doesn't provide anymore any additional functionality on top ofandroidx.lifecycle.lifecycle-common, so dependency on it can be replaced byandroidx.lifecycle.lifecycle-common. ( I021aa ) - Non coroutines API from
lifecycle-viewmodel-ktxhave been moved to thelifecycle-viewmodelmodule. ( I6d5b2 )
External Contribution
Version 2.4.0-alpha03
۴ آگوست ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha03 is released. Version 2.4.0-alpha03 contains these commits.
تغییرات API
- Source-breaking change : ViewModelProvider has been rewritten in Kotlin.
ViewModelProvider.Factory.createmethod no longer allows nullable generic. ( I9b9f6 )
تغییرات رفتاری
- The
Lifecycle.repeatOnLifecycle:blockis now always invoked serially when repeating execution. ( Ibab33 )
External Contribution
- Thanks chao2zhang for fixing the code snippets in the
repeatOnLifecycledocumentation. #205 .
Version 2.4.0-alpha02
۱۶ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha02 is released. Version 2.4.0-alpha02 contains these commits.
ویژگیهای جدید
- Added a new
RepeatOnLifecycleWrongUsagelint check tolifecycle-runtime-ktxthat detects whenrepeateOnLifecycleis incorrectly used inonStart()oronResume(). ( 706078 , b/187887400 )
تغییرات API
- The
LifecycleOwner.addRepeatingJobAPI is removed in favor ofLifecycle.repeatOnLifecyclethat respects structured concurrency and is easier to reason about. ( I4a3a8 ) - Make
ProcessLifecycleInitializerpublic so otherandroidx.startup.Initializers can use these as dependencies. ( I94c31 )
رفع اشکالات
- Fixed an issue with the
NullSafeMutableLiveDatalint check when the field has modifiers. ( #147 , b/183696616 ) - Fixed another issue with the
NullSafeMutableLiveDatalint check when using generics. ( #161 , b/184830263 )
External Contribution
- Thanks maxsav for improving the
NullSafeMutableLiveDatalint check. ( #147 , b/183696616 ) - Thanks kozaxinan for improving the
NullSafeMutableLiveDatalint check. ( #161 , b/184830263 )
Version 2.4.0-alpha01
۲۴ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha01 is released. Version 2.4.0-alpha01 contains these commits.
تغییرات رفتاری
lifecycle-processnow usesandroidx.startupto initialize theProcessLifecycleOwner.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer.If you used
tools:node="remove"theContentProviderbeing used to initialize process lifecycle in the past, then you need to do the following instead.<provider android:name="androidx.startup.InitializationProvider" android:authorities=\"${applicationId}.androidx-startup" android:exported="false" tools:node=\"merge"> <!-- If you are using androidx.startup to initialize other components --> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" tools:node="remove" /> </provider>(یا)
<!-- If you want to disable androidx.startup completely. --> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="remove"> </provider>
تغییرات API
- Added a
Flow.flowWithLifecycleAPI that emits values from the upstream Flow when the lifecycle is at least in a certain state using theLifecycle.repeatOnLifecycleAPI. This is an alternative to the also newLifecycleOwner.addRepeatinJobAPI. ( I0f4cd )
رفع اشکالات
- From Lifecycle 2.3.1 : The
NonNullableMutableLiveDatalint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
Lifecycle Viewmodel Compose Version 1.0.0
Version 1.0.0-alpha07
۱۶ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07 is released. Version 1.0.0-alpha07 contains these commits.
Breaking API Changes
-
viewModel()now takes an optionalViewModelStoreOwner, making it easier to work with owners other than theLocalViewModelStoreOwner. For example, you can now useviewModel(navBackStackEntry)to retrieve a ViewModel associated with a particular navigation graph. ( I2628d , b/188693123 )
Version 1.0.0-alpha06
۲ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha06 is released. Version 1.0.0-alpha06 contains these commits.
Updated to be compatible with Compose version 1.0.0-beta08 .
Version 1.0.0-alpha05
۱۸ مه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits.
ویژگیهای جدید
- Updated to be compatible with Compose version
1.0.0-beta07.
رفع اشکالات
- The AndroidManifest files from ui-test-manifest and ui-tooling-data are now compatible with Android 12 ( I6f9de , b/184718994 )
Version 1.0.0-alpha04
۷ آوریل ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04 is released. Version 1.0.0-alpha04 contains these commits.
تغییرات وابستگی
- This version allows
androidx.hilt:hilt-navigation-composeandandroidx.navigation:navigation-composeto sync dependencies onandroidx.compose.compiler:compiler:1.0.0-beta04andandroidx.compose.runtime:runtime:1.0.0-beta04. For 1.0.0, it is required that the compiler and runtime match.
Version 1.0.0-alpha03
۱۰ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03 is released. Version 1.0.0-alpha03 contains these commits.
تغییرات API
-
LocalViewModelStoreOwner.currentnow returns a nullableViewModelStoreOwnerto better determine whether aViewModelStoreOwneris available in the current composition. APIs that require aViewModelStoreOwner, such asviewModel()andNavHost, still throw an exception if aViewModelStoreOwneris not set. ( Idf39a )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha02
۲۴ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02 is released. Version 1.0.0-alpha02 contains these commits.
تغییرات API
-
LocalViewModelStoreOwnernow has aprovidesfunctions that can be used withCompositionLocalProvider, replacing theasProvidableCompositionLocal()API. ( I45d24 )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha01
۱۰ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01 is released. Version 1.0.0-alpha01 contains these commits.
ویژگیهای جدید
- The
viewModel()composable andLocalViewModelStoreOwnerwere moved fromandroidx.compose.ui.viewinteropto this artifact in theandroidx.lifecycle.viewmodel.composepackage. ( I7a374 )
نسخه ۲.۳.۱
Lifecycle Version 2.3.1
۲۴ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.3.1 is released. Version 2.3.1 contains these commits.
رفع اشکالات
- The
NonNullableMutableLiveDatalint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
نسخه ۲.۳.۰
نسخه ۲.۳.۰
۱۰ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.3.0 is released. Version 2.3.0 contains these commits.
Major changes since 2.2.0
-
SavedStateHandlesupport for non-parcelable classes :SavedStateHandlenow supports lazy serialization by allowing you to callsetSavedStateProvider()for a given key, providing aSavedStateProviderthat will get a callback tosaveState()when theSavedStateHandleis asked to save its state. See Saving non-parcelable classes . - Lifecycle Behavior Enforcement :
- LifecycleRegistry now enforces
DESTROYEDas a terminal state. -
LifecycleRegistrynow verifies that its methods are called on main thread. It was always a requirement for lifecycles of activities, fragments etc. An addition of observers from non-main threads resulted in hard to catch crashes in runtime. ForLifecycleRegistryobjects that owned by your own components, you can explicitly opt out from checks by usingLifecycleRegistry.createUnsafe(...), but then you have to ensure that a proper synchronization is in place when thisLifecycleRegistryis accessed from different threads.
- LifecycleRegistry now enforces
- Lifecycle State and Event Helpers : Added static helper methods of
downFrom(State),downTo(State),upFrom(State),upTo(State)toLifecycle.Eventfor generating theEventgiven aStateand transition direction. Added thegetTargetState()method that provides theStatethat the Lifecycle will transition to directly following theEvent. -
withStateAtLeast: AddedLifecycle.withStateAtLeastAPIs that await a lifecycle state and run a non-suspending block of code synchronously at the point of state change, then resume with the result. These APIs differ from the existingwhen*methods as they do not permit running suspending code and do not employ a custom dispatcher. ( aosp/1326081 ) -
ViewTreeAPIs : A newViewTreeLifecycleOwner.get(View)andViewTreeViewModelStoreOwner.get(View)API allows you to retrieve the containingLifecycleOwnerandViewModelStoreOwner, respectively, given aViewinstance. You must upgrade to Activity1.2.0and Fragment1.3.0, and AppCompat 1.3.0-alpha01 or higher to populate this correctly. ThefindViewTreeLifecycleOwnerandfindViewTreeViewModelStoreOwnerKotlin extensions are available inlifecycle-runtime-ktxandlifecycle-viewmodel-ktx, respectively. -
LiveData.observe()Kotlin extension deprecation : TheLiveData.observe()Kotlin extension necessary to use lambda syntax is now deprecated as it is not necessary when using Kotlin 1.4.
Version 2.3.0-rc01
۱۶ دسامبر ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-rc01 is released. Version 2.3.0-rc01 contains these commits.
رفع اشکالات
- The
keys()method ofSavedStateHandleis now consistent before and after the state is saved - it now includes keys previously used withsetSavedStateProvider()in addition to the keys used withset()andgetLiveData(). ( aosp/1517919 , b/174713653 )
External Contribution
- The APIs to suspend Lifecycle-aware coroutines now better handle calls to
yield(). Thanks Nicklas Ansman Giertz! ( aosp/1430830 , b/168777346 )
Version 2.3.0-beta01
۱ اکتبر ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-beta01 is released. Version 2.3.0-beta01 contains these commits.
تغییرات API
- The
LiveData.observe()Kotlin extension necessary to use lambda syntax is now deprecated as it is not necessary when using Kotlin 1.4. ( I40d3f )
رفع اشکالات
- Upgrade androidx to use Kotlin 1.4 ( Id6471 , b/165307851 , b/165300826 )
Documentation Changes
- The
liveDatabuilder andasLiveData()docs have been updated to include details about changing the given timeout values. ( aosp/1122324 )
Version 2.3.0-alpha07
۱۹ آگوست ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha07 is released. Version 2.3.0-alpha07 contains these commits.
رفع اشکالات
- Fixed a crash issue in the
NullSafeMutableLiveDataLint check. ( aosp/1395367 )
Version 2.3.0-alpha06
۲۲ ژوئیه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha06 is released. Version 2.3.0-alpha06 contains these commits.
ویژگیهای جدید
- Added static helper methods of
downFrom(State),downTo(State),upFrom(State),upTo(State)toLifecycle.Eventfor generating theEventgiven aStateand transition direction. Added thegetTargetState()method that provides theStatethat the Lifecycle will transition to directly following theEvent. ( I00887 ) - Added
Lifecycle.withStateAtLeastAPIs that await a lifecycle state and run a non-suspending block of code synchronously at the point of state change, then resume with the result. These APIs differ from the existingwhen*methods as they do not permit running suspending code and do not employ a custom dispatcher. ( aosp/1326081 )
تغییرات رفتاری
- LifecycleRegistry now enforces
DESTROYEDas a terminal state. ( I00887 ) -
LifecycleRegistrynow verifies that its methods are called on main thread. It was always a requirement for lifecycles of activities, fragments etc. An addition of observers from non-main threads resulted in hard to catch crashes in runtime. ForLifecycleRegistryobjects that owned by your own components, you can explicitly opt out from checks by usingLifecycleRegistry.createUnsafe(...), but then you have to ensure that a proper synchronization is in place when thisLifecycleRegistryis accessed from different threads ( Ie7280 , b/137392809 )
رفع اشکالات
- Fixed a crash in
NullSafeMutableLiveData. ( b/159987480 ) - Fixed an
ObsoleteLintCustomCheckfor Lint checks bundled withlifecycle-livedata-core-ktx(and specificallyNullSafeMutableLiveData). ( b/158699265 )
Version 2.3.0-alpha05
۲۴ ژوئن ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha05 is released. Version 2.3.0-alpha05 contains these commits.
رفع اشکالات
-
LiveDatanow better handles reentrant cases, avoiding duplicate calls toonActive()oronInactive(). ( b/157840298 ) - Fixed an issue where Lint checks would not run when using Android Studio 4.1 Canary 6 or higher. ( aosp/1331903 )
Version 2.3.0-alpha04
۱۰ ژوئن ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha04 is released. Version 2.3.0-alpha04 contains these commits.
رفع اشکالات
- Fixed a crash in the
NonNullableMutableLiveDataLint check. ( b/157294666 ) - The
NonNullableMutableLiveDataLint check now covers significantly more cases where anullvalue was set on aMutableLiveDatawith a non-null type parameter. ( b/156002218 )
Version 2.3.0-alpha03
۲۰ مه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha03 are released. Version 2.3.0-alpha03 contains these commits.
ویژگیهای جدید
-
SavedStateHandlenow supports lazy serialization by allowing you to callsetSavedStateProvider()for a given key, providing aSavedStateProviderthat will get a callback tosaveState()when theSavedStateHandleis asked to save its state. ( b/155106862 ) - A new
ViewTreeViewModelStoreOwner.get(View)API allows you to retrieve the containingViewModelStoreOwnergiven aViewinstance. You must upgrade to Activity1.2.0-alpha05, Fragment1.3.0-alpha05, and AppCompat1.3.0-alpha01to populate this correctly. AfindViewModelStoreOwner()Kotlin extension has been added tolifecycle-viewmodel-ktx. ( aosp/1295522 )
رفع اشکالات
- Fixed an issue that caused the
MutableLiveDataLint checks released in Lifecycle2.3.0-alpha01from being published alongside thelifecycle-livedata-core-ktxartifact. ( b/155323109 )
Version 2.3.0-alpha02
۲۹ آوریل ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha02 is released. Version 2.3.0-alpha02 contains these commits.
تغییرات API
-
SavedStateViewModelFactorynow allows you to pass a nullApplicationto its constructor to better support cases where one is not readily available and support forAndroidViewModelis not needed. ( aosp/1285740 )
رفع اشکالات
- Improved cold start performance by avoiding class verification failure on API 28 and lower devices. ( aosp/1282118 )
Version 2.3.0-alpha01
۴ مارس ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha01 is released. Version 2.3.0-alpha01 contains these commits.
ویژگیهای جدید
- A new
ViewTreeLifecycleOwner.get(View)API allows you to retrieve the containingLifecycleOwnergiven aViewinstance. You must upgrade to Activity1.2.0-alpha01and Fragment1.3.0-alpha01to populate this correctly. AfindViewTreeLifecycleOwnerKotlin extension is available inlifecycle-runtime-ktx. ( aosp/1182361 , aosp/1182956 ) - Added a new Lint check that warns you when setting a
nullvalue on aMutableLiveDatathat has been defined in Kotlin as non-null. This is available when using thelivedata-core-ktxorlivedata-ktxartifacts. ( aosp/1154723 , aosp/1159092 ) - A new
lifecycle-runtime-testingartifact is available that provides aTestLifecycleOwnerthat implementsLifecycleOwnerand provides a thread safe mutableLifecycle. ( aosp/1242438 )
رفع اشکالات
- The
lifecycle-runtimeartifact now has a unique package name. ( aosp/1187196 )
نسخه ۲.۲.۰
ViewModel-Savedstate Version 2.2.0
۵ فوریه ۲۰۲۰
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0 is released. Version 2.2.0 contains these commits .
Lifecycle ViewModel SavedState now shares the same version as other Lifecycle artifacts. The behavior of 2.2.0 is identical to the behavior of 1.0.0 .
نسخه ۲.۲.۰
۲۲ ژانویه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.2.0 is released. Version 2.2.0 contains these commits .
Important changes since 2.1.0
- Lifecycle Coroutine Integration : The new
lifecycle-runtime-ktxartifact adds integration between Lifecycle and Kotlin coroutines. Thelifecycle-livedata-ktxhas also been expanded to take advantage of coroutines. See Use Kotlin coroutines with Architecture Components for more details. -
ViewModelProviders.of()deprecation :ViewModelProviders.of()has been deprecated. You can pass aFragmentorFragmentActivityto the newViewModelProvider(ViewModelStoreOwner)constructor to achieve the same functionality when using Fragment1.2.0. -
lifecycle-extensionsArtifact Deprecation : With the above deprecation ofViewModelProviders.of(), this release marks the deprecation of the last API inlifecycle-extensionsand this artifact should now be considered deprecated in its entirety. We strongly recommend depending on the specific Lifecycle artifacts you need (such aslifecycle-serviceif you're usingLifecycleServiceandlifecycle-processif you're usingProcessLifecycleOwner) rather thanlifecycle-extensionsas there will not be a future2.3.0release oflifecycle-extensions. - Gradle Incremental Annotation Processor : Lifecycle's annotation processor is incremental by default. If your app is written in the Java 8 programming language you can use
DefautLifecycleObserverinstead; and if it's written in the Java 7 programming language you can useLifecycleEventObserver.
Version 2.2.0-rc03
۴ دسامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc03 is released. Version 2.2.0-rc03 contains these commits .
رفع اشکالات
- Fixed a failure occurring when a mocked
ViewModelwas stored inViewModelStoreand queried later with default factory. - Fix a usage of
Dispatchers.Main.immediateinlaunchWhenCreatedand similar methods to be called synchronously during corresponding lifecycle event. ( aosp/1156203 )
مشارکتهای خارجی
- Thanks to Anders Järleberg for contributing the fix! ( aosp/1156203 )
- Thanks to Vsevolod Tolstopyatov from Jetbrains for reviewing an implementation of inlined execution.
Dependency changes
- Lifecycle Extensions now depends on Fragment
1.2.0-rc03.
Version 2.2.0-rc02
۷ نوامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc02 is released. Version 2.2.0-rc02 contains these commits .
رفع اشکالات
- Fixed a bug in the proguard setup of the library that affected devices running API 28+ if the target API is below 29. ( b/142778206 )
Version 2.2.0-rc01
۲۳ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc01 is released. Version 2.2.0-rc01 contains these commits .
رفع اشکالات
- Fixed an issue where
launchWhenCreatedand related methods would run one frame later than the associated lifecycle method due to its use ofDispatchers.Maininstead ofDispatchers.Main.immediate. ( aosp/1145596 )
مشارکتهای خارجی
- Thanks to Nicklas Ansman for contributing the fix! ( aosp/1145596 )
Version 2.2.0-beta01
۹ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-beta01 is released. Version 2.2.0-beta01 contains these commits .
رفع اشکالات
- Fixed a regression introduced in Lifecycle 2.2.0-alpha05 in the ordering of
ProcessLifecycleOwnerand the activity'sLifecycleOwnermoving to started and resumed on Android 10 devices. ( aosp/1128132 ) - Fixed a regression introduced in Lifecycle
2.2.0-alpha05which would cause aNullPointerExceptionwhen using version2.0.0or2.1.0oflifecycle-process. ( b/141536990 )
Version 2.2.0-alpha05
۱۸ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha05 is released. Version 2.2.0-alpha05 contains these commits .
رفع اشکالات
- Fixed a race condition in coroutine livedata builder. b/140249349
Version 2.2.0-alpha04
۵ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha04 is released. The commits included in this version can be found here .
ویژگیهای جدید
-
lifecycleScope,whenCreated,whenStarted,whenResumed,viewModelScope, and the underlying implementation ofliveDatanow useDispatchers.Main.immediateinstead ofDispatchers.Main. ( b/139740492 )
مشارکتهای خارجی
- Thanks to Nicklas Ansman for contributing the move to
Dispatchers.Main.immediate! ( aosp/1106073 )
Version 2.2.0-alpha03
۷ آگوست ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha03 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Implementations of
ViewModelStoreOwnercan now optionally implementHasDefaultViewModelProviderFactoryto provide a defaultViewModelProvider.Factory. This has been done for Activity1.1.0-alpha02, Fragment1.2.0-alpha02, and Navigation2.2.0-alpha01. ( aosp/1092370 , b/135716331 )
API changes
-
ViewModelProviders.of()has been deprecated. You can pass aFragmentorFragmentActivityto the newViewModelProvider(ViewModelStoreOwner)constructor to achieve the same functionality. ( aosp/1009889 )
Version 2.2.0-alpha02
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:*:2.2.0-alpha02 is released. The commits included in this version can be found here .
API changes
- Replaced
LiveDataScope.initialValuewithLiveDataScope.latestValuewhich will track the current emitted value of theliveDatablock. - Added a new overload to the
liveDatabuilder that receivestimeoutparameter as typeDuration
Version 2.2.0-alpha01
۷ مه ۲۰۱۹
androidx.lifecycle:*:2.2.0-alpha01 is released. The commits included in this version can be found here .
ویژگیهای جدید
- This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here .
ViewModel-SavedState Version 1.0.0
نسخه ۱.۰.۰
۲۲ ژانویه ۲۰۲۰
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0 is released. Version 1.0.0 contains these commits .
Important features in 1.0.0
- New SavedStateHandle class was added. It enables your
ViewModelclasses to access and to contribute to the saved state. This object can be received in constructor ofViewModelclass and factories provided by default by Fragments and AppCompatActivity will injectSavedStateHandleautomatically. - AbstractSavedStateViewModelFactory was added. It allows you to create custom factories for your
ViewModeland provide them access toSavedStateHandle.
ViewModel-Savedstate Version 1.0.0-rc03
۴ دسامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc03 is released. Version 1.0.0-rc03 contains these commits .
Dependency changes
- Lifecycle ViewModel SavedState now depends on Lifecycle
2.2.0-rc03.
Viewmodel-Savedstate Version 1.0.0-rc02
۷ نوامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc02 is released. Version 1.0.0-rc02 contains these commits .
Dependency changes
- Now depends on lifecycle
2.2.0-rc02.
ViewModel-SavedState Version 1.0.0-rc01
۲۳ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc01 is released with no changes from 1.0.0-beta01 . Version 1.0.0-rc01 contains these commits .
ViewModel-Savedstate Version 1.0.0-beta01
۹ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01 is released. Version 1.0.0-beta01 contains these commits .
رفع اشکالات
- Fixed an issue where accessing a SavedState ViewModel for the first time in
Activity.onActivityResult()would result in anIllegalStateException. ( b/139093676 ) - Fixed an
IllegalStateExceptionwhen usingAbstractSavedStateViewModelFactory. ( b/141225984 )
ViewModel-SavedState Version 1.0.0-alpha05
۱۸ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits .
API changes
-
SavedStateViewModelFactoryno longer extendsAbstractSavedStateViewModelFactoryandSavedStateHandleis created only for ViewModels that requested have it ( aosp/1113593 )
ViewModel-SavedState Version 1.0.0-alpha03
۷ آگوست ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03 is released. The commits included in this version can be found here .
تغییرات اساسی
-
lifecycle-viewmodel-savedstateno longer depends onfragmentand the relatedSavedStateViewModelFactory(Fragment)andSavedStateViewModelFactory(FragmentActivity)constructors have been removed. Instead,SavedStateViewModelFactoryis now the default factory for Activity1.1.0-alpha02, Fragment1.2.0-alpha02, and Navigation2.2.0-alpha01. ( b/135716331 )
ViewModel-SavedState Version 1.0.0-alpha02
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha02 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Added
SavedStateHandle.getLiveData()overload which accepts a default value.
تغییرات API
-
SavedStateVMFactoryis renamed toSavedStateViewModelFactory. -
AbstractSavedStateVMFactoryis renamed toAbstractSavedStateViewModelFactory.
ViewModel-Savedstate Version 1.0.0-alpha01
۱۳ مارس ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01 is released. The full commit log for this initial release can be found here .
ویژگیهای جدید
- Now
ViewModelscan contribute to savedstate. To do that you use newly introduced viewmodel's factorySavedStateVMFactoryand your ViewModel should have a constructor that receivesSavedStateHandleobject as a parameter.
نسخه ۲.۱.۰
Important changes since 2.0.0
- Added
LifecycleEventObserverfor the cases when a stream of lifecycle events is needed. It is a public API instead of a hiddenGenericLifecycleObserverclass. - Added ktx extensions for
LiveData.observemethods andTransformations.*methods. - Added
Transformations.distinctUntilChanged, which creates a new LiveData object that does not emit a value until the sourceLiveDatavalue has been changed. - Added coroutine support in ViewModels by adding the extension property
ViewModel.viewModelScope.
نسخه ۲.۱.۰
۵ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.1.0 is released. The commits included in this version can be found here .
Version 2.1.0-rc01
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:*:2.1.0-rc01 is released with no changes from androidx.lifecycle:*:2.1.0-beta01 . The commits included in this version can be found here .
Version 2.1.0-beta01
۷ مه ۲۰۱۹
androidx.lifecycle:*:2.1.0-beta01 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Lifecycles are graduated to beta: api introduced in previous alphas such as
liveDataextension functions for transformations and observations,ViewModelinitialisation with property delegation and others are stabilised and not going to change.
Version 2.1.0-alpha04
۳ آوریل ۲۰۱۹
androidx.lifecycle:*:2.1.0-alpha04 is released. The commits included in this version can be found here .
API changes
- Breaking change: the underlying API behind
by viewModels()andby activityViewModels()has been changed to support aViewModelStoredirectly, rather than only aViewModelStoreOwner. ( aosp/932932 )
Version 2.1.0-alpha03
۱۳ مارس ۲۰۱۹
androidx.lifecycle:*:2.1.0-alpha03 is released. The full list of commits included in this version can be found here .
API changes
-
ViewModelProvider.KeyedFactorywas removed. Second interface in addition toViewModelProvider.Factorydidn't compose well with new features as property delegation in Kotlinby viewmodels {}. ( aosp/914133 )
Version 2.1.0-alpha02
۳۰ ژانویه ۲۰۱۹
androidx.lifecycle 2.1.0-alpha02 is released.
API changes
-
LifecycleRegistrynow contains asetCurrentState()method that replaces the now deprecatedsetState()method. ( aosp/880715 )
رفع اشکالات
- Fixed an issue where mock
ViewModelinstances would crash when the containingViewModelStorewas cleared. b/122273087
Version 2.1.0-alpha01
۱۷ دسامبر ۲۰۱۸
androidx.lifecycle 2.1.0-alpha01 is released.
ویژگیهای جدید
- Added
LifecycleEventObserverfor the cases when a stream of lifecycle events is needed. It is a public api instead of a hiddenGenericLifecycleObserverclass. - Added ktx extensions for
LiveData.observemethods andTransformations.*methods. - Method
Transformations.distinctUntilChangedwas added. It creates a newLiveDataobject that does not emit a value until the source LiveData value has been changed. - Coroutine support in ViewModels: extension property
ViewModel.viewModelScopewas added. - Added
ViewModelProvider.KeyedFactory, a factory for ViewModels that receiveskeyandClassincreatemethod.
نسخه ۲.۰.۰
نسخه ۲.۰.۰
۲۱ سپتامبر ۲۰۱۸
Lifecycle 2.0.0 is released with one bugfix from 2.0.0-rc01 in ViewModel.
رفع اشکالات
- Fixed a ViewModel proguard rule that incorrectly removed constructors b/112230489
Version 2.0.0-beta01
July 2, 2018
رفع اشکالات
- Fixed LifecycleObserver proguard rule to keep only implementations, not subinterfaces b/71389427
- Fixed ViewModel proguard rules to allow obfuscation and shrinking
Pre-AndroidX Versions
For the pre-AndroidX versions of Lifecycle that follow, include these dependencies:
dependencies {
def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// alternatively - just ViewModel
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version" // For Kotlin use viewmodel-ktx
// alternatively - just LiveData
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
// alternatively - Lifecycles only (no ViewModel or LiveData).
// Support library depends on this lightweight import
implementation "android.arch.lifecycle:runtime:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" // For Kotlin use kapt instead of annotationProcessor
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
// optional - ReactiveStreams support for LiveData
implementation "android.arch.lifecycle:reactivestreams:$lifecycle_version"
// optional - Test helpers for LiveData
testImplementation "android.arch.core:core-testing:$lifecycle_version"
}
نسخه ۱.۱.۱
۲۱ مارس ۲۰۱۸
Only one small change: android.arch.core.util.Function is moved from arch:runtime to arch:common . This allows it to be used without the runtime dependency, eg in paging:common below.
lifecycle:common is a dependency of lifecycle:runtime , so this change doesn't affect lifecycle:runtime directly, only modules that depend directly on lifecycle:common , as Paging does.
نسخه ۱.۱.۰
۲۲ ژانویه ۲۰۱۸
Packaging Changes
New, much smaller dependencies are now available:
-
android.arch.lifecycle:livedata:1.1.0 -
android.arch.lifecycle:viewmodel:1.1.0
تغییرات API
- The deprecated
LifecycleActivityandLifecycleFragmenthave now been removed - please useFragmentActivity,AppCompatActivityor supportFragment. -
@NonNullannotations have been added toViewModelProvidersandViewModelStores -
ViewModelProvidersconstructor has been deprecated - please use its static methods directly -
ViewModelProviders.DefaultFactoryhas been deprecated - please useViewModelProvider.AndroidViewModelFactory - The static
ViewModelProvider.AndroidViewModelFactory.getInstance(Application)method has been added to retrieve a staticFactorysuitable for creatingViewModelandAndroidViewModelinstances.
چرخه حیات
This table lists all the artifacts in the androidx.lifecycle group.
| مصنوع | انتشار پایدار | کاندیدای انتشار | انتشار بتا | انتشار آلفا |
|---|---|---|---|---|
| lifecycle-* | ۲.۹.۴ | 2.10.0-rc01 | - | - |
| lifecycle-viewmodel-navigation3 | - | 2.10.0-rc01 | - | - |
اعلام وابستگیها
To add a dependency on Lifecycle, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
وابستگیهای مربوط به مصنوعات مورد نیاز خود را در فایل build.gradle برای برنامه یا ماژول خود اضافه کنید:
کاتلین
شیار
dependencies { def lifecycle_version = "2.9.4" def arch_version = "2.2.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // ViewModel utilities for Compose implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" // Lifecycle utilities for Compose implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version" // Saved state module for ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" // ViewModel integration with Navigation3 implementation "androidx.lifecycle:lifecycle-viewmodel-navigation3:2.10.0-rc01" // Annotation processor kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" // alternately - if using Java8, use the following instead of lifecycle-compiler implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // optional - helpers for implementing LifecycleOwner in a Service implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version" // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version" // optional - ReactiveStreams support for LiveData implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version" // optional - Test helpers for LiveData testImplementation "androidx.arch.core:core-testing:$arch_version" // optional - Test helpers for Lifecycle runtime testImplementation "androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version" }
کاتلین
dependencies { val lifecycle_version = "2.9.4" val arch_version = "2.2.0" // ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") // ViewModel utilities for Compose implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version") // LiveData implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") // Lifecycles only (without ViewModel or LiveData) implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version") // Lifecycle utilities for Compose implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version") // Saved state module for ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version") // ViewModel integration with Navigation3 implementation("androidx.lifecycle:lifecycle-viewmodel-navigation3:2.10.0-rc01") // Annotation processor kapt("androidx.lifecycle:lifecycle-compiler:$lifecycle_version") // alternately - if using Java8, use the following instead of lifecycle-compiler implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version") // optional - helpers for implementing LifecycleOwner in a Service implementation("androidx.lifecycle:lifecycle-service:$lifecycle_version") // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation("androidx.lifecycle:lifecycle-process:$lifecycle_version") // optional - ReactiveStreams support for LiveData implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version") // optional - Test helpers for LiveData testImplementation("androidx.arch.core:core-testing:$arch_version") // optional - Test helpers for Lifecycle runtime testImplementation ("androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version") }
جاوا
شیار
dependencies { def lifecycle_version = "2.9.4" def arch_version = "2.2.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" // Saved state module for ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" // Annotation processor annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" // alternately - if using Java8, use the following instead of lifecycle-compiler implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // optional - helpers for implementing LifecycleOwner in a Service implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version" // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version" // optional - ReactiveStreams support for LiveData implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version" // optional - Test helpers for LiveData testImplementation "androidx.arch.core:core-testing:$arch_version" // optional - Test helpers for Lifecycle runtime testImplementation "androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version" }
کاتلین
dependencies { val lifecycle_version = "2.9.4" val arch_version = "2.2.0" // ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version") // LiveData implementation("androidx.lifecycle:lifecycle-livedata:$lifecycle_version") // Lifecycles only (without ViewModel or LiveData) implementation("androidx.lifecycle:lifecycle-runtime:$lifecycle_version") // Saved state module for ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version") // Annotation processor annotationProcessor("androidx.lifecycle:lifecycle-compiler:$lifecycle_version") // alternately - if using Java8, use the following instead of lifecycle-compiler implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version") // optional - helpers for implementing LifecycleOwner in a Service implementation("androidx.lifecycle:lifecycle-service:$lifecycle_version") // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process implementation("androidx.lifecycle:lifecycle-process:$lifecycle_version") // optional - ReactiveStreams support for LiveData implementation("androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version") // optional - Test helpers for LiveData testImplementation("androidx.arch.core:core-testing:$arch_version") // optional - Test helpers for Lifecycle runtime testImplementation("androidx.lifecycle:lifecycle-runtime-testing:$lifecycle_version") }
For more information about dependencies, see Add Build Dependencies .
بازخورد
بازخورد شما به بهبود Jetpack کمک میکند. اگر مشکلات جدیدی کشف کردید یا ایدههایی برای بهبود این کتابخانه دارید، به ما اطلاع دهید. لطفاً قبل از ایجاد یک کتابخانه جدید، نگاهی به مشکلات موجود در این کتابخانه بیندازید. میتوانید با کلیک بر روی دکمه ستاره، رأی خود را به یک مشکل موجود اضافه کنید.
برای اطلاعات بیشتر به مستندات ردیاب مشکل مراجعه کنید.
Version 2.10
Version 2.10.0-rc01
۵ نوامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-rc01 is released. Version 2.10.0-rc01 contains these commits .
Version 2.10.0-beta01
۲۲ اکتبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-beta01 is released. Version 2.10.0-beta01 contains these commits .
تغییرات API
-
ViewModelStoreNavEntryDecoratorDefaulthas been renamed toViewModelStoreNavEntryDecoratorDefaults, with an 's'. ( I6d27b , b/444447434 )
رفع اشکالات
-
rememberLifecycleOwnerno longer crashes if the owner receives anLifecycle.Event.ON_DESTROYevent before moving toLifeycle.State.CREATED. ( I6f98e , b/444594991 )
Version 2.10.0-alpha05
۸ اکتبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha05 is released. Version 2.10.0-alpha05 contains these commits .
تغییرات API
- The
removeViewModelStoreOnPopCallback()is now part of aViewModelStoreNavEntryDecoratorDefaultobject which is where other platforms and implementations can call the default. ( Ia1f23 , b/444447434 ) - Refactored
ViewModelStoreNavEntryDecoratorfrom a function to a class to better reflect its functionality as a factory forNavEntryDecorator, and renamed the decorator'sshouldRemoveViewModelStoreparameter toremoveViewModelStoreOnPopto clarify that this callback is invoked only when an entry is popped from thebackStack. ( Iefdc5 , b/444447434 )
Version 2.10.0-alpha04
۲۴ سپتامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha04 is released. Version 2.10.0-alpha04 contains these commits .
تغییرات API
- Refactor the
LifecycleOwnercomposable torememberLifecycleOwner. The function now returns theLifecycleOwnerdirectly. To provide this owner to a sub-composition, useCompositionLocalProvider. ( Ic57f0 , b/444446629 ) - Add KMP stubs to lifecycle-viewmodel-navigation3 to enable JetBrains to provide forks that fill these targets and thus support CMP. ( I44a4c )
Version 2.10.0-alpha03
۲۷ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha03 is released. Version 2.10.0-alpha03 contains these commits .
تغییرات API
- Update Compose to 1.9.0. ( I2b9de )
Version 2.10.0-alpha02
۱۳ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha02 is released. Version 2.10.0-alpha02 contains these commits .
ویژگیهای جدید
The
LifecycleOwnercomposable can now create a standalone root lifecycle . By (explicitly) settingparent = null, the new lifecycle operates independently of any host (like anActivity,FragmentorNavBackStackEntry). It starts as soon as the composable enters the composition and is automatically destroyed when it leaves. ( I8dfbe , b/433659048 )@Composable fun IndependentComponent() { // Create a standalone lifecycle, not tied to the parent Activity/Fragment. LifecycleOwner(parent = null) { val rootLifecycle = LocalLifecycleOwner.current.lifecycle } }
تغییرات API
- In the
LifecycleOwnercomposable, theparentLifecycleOwnerparameter has been renamed toparent. ( I080bc )
رفع اشکالات
-
LifecycleOwnercomposable now correctly moves its lifecycle toDESTROYEDupon disposal. This prevents potential leaks for external code that holds a reference to the lifecycle. ( I9e5b7 , b/433659048 ) - Moving the default minSdk from API 21 to API 23 ( Ibdfca , b/380448311 , b/435705964 , b/435705223 )
External Contribution
- Remove unnecessary internal backing fields from
LifecycleOwner. Thanks Jake Wharton for the contribution. ( Ideddb )
Version 2.10.0-alpha01
۳۰ ژوئیه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.10.0-alpha01 is released. Version 2.10.0-alpha01 contains these commits .
ویژگیهای جدید
Add a
LifecycleOwnercomposable to enable creating scoped lifecycles directly within the UI. This is useful for components that need to manage their own lifecycles independently. For an example of how Navigation3 integrates this new composable, see aosp/3708610 . ( 76cbf7 )@Composable fun MyComposable() { LifecycleOwner( maxLifecycle = RESUMED, parentLifecycleOwner = LocalLifecycleOwner.current, ) { val childLifecycleOwner = LocalLifecycleOwner.current } }
تغییرات API
- Add a builder factory function for
CreationExtras, providing a more convenient and idiomatic Kotlin API. ( Iab2bd ) - Add native support for nullable types in
SavedStateHandle.saved, simplifying saving and restoring nullable properties. ( I54d69 , b/421325690 ) - Mark
SavedStateHandleconstructors as@VisibleForTesting. ( Iff0e0 , b/408002794 )
نسخه ۲.۹
Version 2.9.4
۱۷ سپتامبر ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.4 is released. Version 2.9.4 contains these commits .
رفع اشکالات
- Fixed an error with the Compose Compiler plugin not being applied that caused Lifecycle KMP artifacts to be broken. ( Ie95bc , b/443096483 , b/443965665 )
Version 2.9.3
۲۷ آگوست ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.3 is released. Version 2.9.3 contains these commits .
ویژگیهای جدید
- Add new Kotlin Multiplatform (KMP) targets to Lifecycle
*-composeartifacts. Lifecycle now supports the following platforms in total: JVM (Android and Desktop), Native (Linux, iOS, watchOS, macOS, MinGW), and Web (JavaScript, WasmJS). ( I0a0e4 )
رفع اشکالات
- Update
androidx.annotationto 1.9.1 ( Ic9e4f , b/397701294 )
نسخه ۲.۹.۲
۱۶ ژوئیه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.2 is released. Version 2.9.2 contains these commits .
رفع اشکالات
- Added new Kotlin Multiplatform (KMP) targets to Lifecycle artifacts. Lifecycle now supports the following platforms in total: JVM (Android and Desktop), Native (Linux, iOS, watchOS, macOS, MinGW), and Web (JavaScript, WasmJS). Note that no new KMP targets have been added to the
*-composeartifacts, as this depends on the stable release of Compose 1.9. ( I01cb8 ).
بهروزرسانیهای وابستگی
- Lifecycle now depends on Annotation
1.9.1to enable support for the new KMP targets ( Ic9e4f , b/397701294 ).
نسخه ۲.۹.۱
۴ ژوئن ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.1 is released. Version 2.9.1 contains these commits .
رفع اشکالات
- Fix
SavedStateHandle.remove(key)not clearingSavedStateHandle.getMutableStateFlow(key)states. ( d5f939 , b/418746333 )
نسخه ۲.۹.۰
۷ مه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0 is released. Version 2.9.0 contains these commits .
Important changes since 2.8.0
- A new
androidx.lifecycle:lifecycle-viewmodel-testingKMP artifact is available that provides aViewModelScenarioclass for testingViewModelsin isolation, with support foronClearedandSavedStateHandleas well as testing process death and recreation viarecreate(). - Add
getMutableStateFlowtoSavedStateHandleto return aMutableStateFlow. This new function is key-exclusive and cannot be used withgetLiveData. An exception will be thrown if you try to use both to access the same state. -
CreationExtrasnow includes map-like operator overloads to enable idiomatic manipulation of content in Kotlin. It allows the use ofin,+=, and+withCreationExtras.
KotlinX Serialization Support
With the support of KotlinX Serialization added in SavedState
1.3.0, we have introducedsaved, a lazy property delegate, to make it easy to store@Serializableclasses in aSavedStateHandleand have those classes automatically be restored across process death and recreation. Please note thesaveddelegate is lazy and will not call theinitlambda or save anything into theSavedStateHandleuntil it is accessed.@Serializable data class Person(val firstName: String, val lastName: String) class MyViewModel(handle: SavedStateHandle) : ViewModel() { var person by handle.saved { Person("John", "Doe") } fun onPersonChanged(person: Person) { this.person = person } }
کاتلین چندسکویی
- The
lifecycle-testingmodule is now KMP compatible including APIs likeTestLifecycleOwner. - The
lifecycle-viewmodel-savedstatemodule is now KMP compatible including APIs likeSavedStateHandle. - The
androidx.compose.ui.platform.LocalLifecycleOwneris now available in the common source set. -
NewInstanceFactoryis now available on JVM Desktop and Android targets.
تغییرات رفتاری
- The
Lifecycle.DESTROYEDstate is terminal, and any attempt to move aLifecyclefrom it to any other state will now result in anIllegalStateException. -
SavedStateHandleno longer includes anySavedStateProvider.saveState()where the returnedBundleis empty.
Version 2.9.0-rc01
۲۳ آوریل ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-rc01 is released. Version 2.9.0-rc01 contains these commits .
Lint API Compatibility Warning
- JetBrains changed
KaCallableMemberCallfrom a class to an interface , which breaks binary compatibility. This can cause crashes if your project's AGP version differs from the version used to compile lint checks. This update was made in aosp/3577172 but was missing from the release notes — we're clarifying it here. Recommended fix: Update to the latest stable AGP. If you can't fully update, useandroid.experimental.lint.versionto align lint checks with your AGP version — see Compose Runtime behavior changes for details.
Version 2.9.0-beta01
۹ آوریل ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-beta01 is released. Version 2.9.0-beta01 contains these commits .
تغییرات API
-
Lifecycle ViewModel Composenow uses the same Kotlin Multiplatform setup as Compose Runtime 1.7.1 and higher - the-desktopartifacts are now removed and-jvmStubsand-linuxx64Stubsartifacts have been added. None of these targets are meant to be used, they are placeholders to help Jetbrains Compose efforts. ( I5cb14 , b/406592090 )
بهروزرسانیهای وابستگی
- This library now targets Kotlin 2.0 language level and requires KGP 2.0.0 or newer. ( Idb6b5 )
-
Lifecycle ViewModel Composenow depends on Compose 1.7.8. ( I5cb14 , b/406592090 )
Version 2.9.0-alpha13
۲۶ مارس ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha13 is released with no notable public changes. Version 2.9.0-alpha13 contains these commits .
Version 2.9.0-alpha12
۱۲ مارس ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha12 is released. Version 2.9.0-alpha12 contains these commits .
تغییرات API
- Add
@MainThreadannotation toViewModelProvider.getin all supported KMP platforms. ( I7e8dd , b/397736115 ) - Rename
SavedState*DelegatestoSavedState*Delegate. ( I8589b , b/399629301 )
Version 2.9.0-alpha11
۲۶ فوریه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha11 is released. Version 2.9.0-alpha11 contains these commits .
تغییرات API
- Add
SavedStateConfigparameter tosaved()delegates ( I39b3a )
Version 2.9.0-alpha10
۱۲ فوریه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha10 is released. Version 2.9.0-alpha10 contains these commits .
تغییرات API
- Move
MutableStateSerializertosavedstate-composefromlifecycle-viewmodel-compose. ( I4f690 , b/378895074 )
External Contribution
- Adds a new Lint issue for calling
Lifecycle::currentStatein composition, instead suggesting usingcurrentStateAsalue().valueto ensure that changes in the Lifecycle state correctly cause recomposition. Thanks Steven Schoen! ( Iad484 )
Version 2.9.0-alpha09
۲۹ ژانویه ۲۰۲۵
androidx.lifecycle:lifecycle-*:2.9.0-alpha09 is released. Version 2.9.0-alpha09 contains these commits .
ویژگیهای جدید
- Add
MutableStateSerializerfor serializingandroidx.compose.runtime.MutableState. ( Idfc48 , b/378895074 )
تغییرات API
- Replace overloaded
SavedStateHandle.saved()delegate functions with default parameters ( Icd1c1 ) -
AbstractSavedStateViewModelFactoryis deprecated as it creates aSavedStateHandlefor everyViewModel, causing unnecessary overhead. UseViewModelProvider.FactorywithCreationExtras.createSavedStateHandleinstead for more efficientViewModelcreation. ( Ia920b , b/388590327 )
Version 2.9.0-alpha08
۱۱ دسامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha08 is released. Version 2.9.0-alpha08 contains these commits .
ویژگیهای جدید
- Add
ViewModelScenario.recreateto simulate a System Process Death recreating theViewModelunder test and all associated components. ( Id6a69 , b/381063087 ) -
LifecycleOwnerandViewModelStoreOwnerinstances retrieved via their respectivefindViewTreeAPIs can now be resolved through disjoint parents of a view, such as aViewOverlay. See the release notes of core or the documentation inViewTree.setViewTreeDisjointParentfor more information on disjoint view parents. ( I800f4 )
تغییرات API
- Make the namings and package organization more consistent with
SavedStateRegistryOwnerDelegate( I8c135 , b/376026744 )
رفع اشکالات
- This library now uses JSpecify nullness annotations , which are type-use. Kotlin developers should use the following compiler argument to enforce correct usage:
-Xjspecify-annotations=strict(this is the default starting with version 2.1.0 of the Kotlin compiler). ( Ie4340 , b/326456246 ) - Document
ViewModel.onClearedclearing sequence. ( I586c7 , b/363984116 )
Version 2.9.0-alpha07
۱۳ نوامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha07 is released. Version 2.9.0-alpha07 contains these commits .
Kotlin Multiplatform Compatibility
- Lifecycle
ViewModel SavedStateis now KMP compatible. This allows you to useSavedStateHandlein common code. ( Ib6394 , b/334076622 )
KotlinX Serialization Support
With the support of KotlinX Serialization added in SavedState
1.3.0-alpha05, we have introducedsaved, a lazy property delegate, to make it easy to store@Serializableclasses in aSavedStateHandleand have those classes automatically be restored across process death and recreation. Please note thesaveddelegate is lazy and will not call theinitlambda or save anything into theSavedStateHandleuntil it is accessed. ( I47a88 , b/376026744 )@Serializable data class Person(val firstName: String, val lastName: String) class MyViewModel(handle: SavedStateHandle) : ViewModel() { var person by handle.saved { Person("John", "Doe") } fun onPersonChanged(person: Person) { this.person = person } }
تغییرات API
- Add
getMutableStateFlowtoSavedStateHandleto return aMutableStateFlow. This new function is key-exclusive and cannot be used withgetLiveData. An exception will be thrown if you try to use both to access the same state. ( I04a4f , b/375408415 )
Version 2.9.0-alpha06
۳۰ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha06 is released. Version 2.9.0-alpha06 contains these commits .
تغییرات رفتاری
- The
Lifecycle.DESTROYEDstate is terminal, and any attempt to move aLifecyclefrom it to any other state will now result in anIllegalStateException. ( I116c4 , b/370577987 ) -
SavedStateHandleno longer includes anySavedStateProvider.saveState()where the returnedBundleis empty. ( I910b5 , b/370577987 )
رفع اشکالات
-
Lifecycle.eventFlownow correctly complete whenLifecycleisDESTROYED( I293b2 , b/374043130 )
Version 2.9.0-alpha05
۱۶ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha05 is released with no notable changes. Version 2.9.0-alpha05 contains these commits .
Version 2.9.0-alpha04
۲ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha04 is released. Version 2.9.0-alpha04 contains these commits .
کاتلین چندسکویی
- The
lifecycle-viewmodel-savedstatemodule is now configured to be KMP compatible in preparation for APIs likeSavedStateHandlebeing made available in the common source set in a future release. ( I503ed , I48764 , b/334076622 )
Version 2.9.0-alpha03
۱۸ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha03 is released. Version 2.9.0-alpha03 contains these commits .
رفع اشکالات
- From Lifecycle
2.8.6: TheNullSafeMutableLiveDataLint error has improved support for smart casts, avoiding false positives. ( 85fed6 , b/181042665 )
بهروزرسانیهای وابستگی
- From Lifecycle
2.8.6: Lifecycle Runtime Compose now depends on Compose Runtime1.7.1 - Lifecycle Runtime now depends on ProfileInstaller
1.4.0
Version 2.9.0-alpha02
۴ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha02 is released. Version 2.9.0-alpha02 contains these commits .
رفع اشکالات
- From Lifecycle
2.8.5: Update theandroidx.lifecycle.ReportFragmentProGuard rules to allow obfuscation . ( ff898e1 )
External Contribution
- Move
androidx.compose.ui.platform.LocalLifecycleOwnerto common source set (KMP). Thanks Ivan Matkov from JetBrains for the contribution. ( 8cd5d03 ) - From Lifecycle
2.8.5: SavedStateHandle.saveable` extension delegate now supports nullable values. Thanks Roman Kalukiewicz for the contribution. ( 0d78ea6 )
Version 2.9.0-alpha01
۷ آگوست ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.9.0-alpha01 is released. Version 2.9.0-alpha01 contains these commits .
کاتلین چندسکویی
-
lifecycle-testingis now KMP compatible. ( Iea41e ) - Add support for
linuxArm64kotlin multiplatform target ( I139d3 , b/338268719 )
ویژگیهای جدید
- A new
androidx.lifecycle:lifecycle-viewmodel-testingKMP artifact is available that provides aViewModelScenarioclass for testing ViewModels in isolation, with support foronCleared(all platforms) andSavedStateHandle(Android only). ( 337f68d , c9b3409 , 9799a95c , b/264602919 ) - Creating a
ViewModelwithViewModelProvideris now thread safe;@MainThreadannotations have been removed. ( Ifd978 , b/237006831 )
تغییرات API
- Add the
CreationExtras.Key()factory function to simplify the creation of anonymousCreationExtras.Keyobjects. ( I970ee ) -
CreationExtrasnow includes map-like operator overloads to enable idiomatic manipulation of content in Kotlin. It allows the use ofin,+=, and+withCreationExtras. ( Ib4353 ) -
CreationExtrasnow implementsequals,hashCode, andtoStringmethods. ( Ib4353 ) -
NewInstanceFactoryis now available on JVM Desktop and Android targets. ( d3d0892 ) - Inline extension property to expose underlying Application safely in Kotlin language version 2.0 ( I39df2 )
رفع اشکالات
- Removed manual outlining of access to new platform APIs since this happens automatically via API modeling when using R8 with AGP 7.3 or later (eg R8 version 3.3) and for all builds when using AGP 8.1 or later (eg D8 version 8.1). Clients who are not using AGP are advised to update to D8 version 8.1 or later. See this article for more details. ( If6b4c , b/345472586 )
نسخه ۲.۸
Version 2.8.7
۳۰ اکتبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.7 is released. Version 2.8.7 contains these commits .
تغییرات API
-
androidx.compose.ui.platform.LocalLifecycleOwneris now available in the common source set (KMP). ( 6a3f5b3 ) -
lifecycle-runtime-compose:desktopartifacts were removed and-jvmStubsand-linuxx64Stubsartifacts were added. None of these targets are meant to be used, they are placeholders to help Jetbrains Compose efforts. ( 6a3f5b3 )
Version 2.8.6
۱۸ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.6 is released. Version 2.8.6 contains these commits .
رفع اشکالات
- The
NullSafeMutableLiveDataLint error has improved support for smart casts, avoiding false positives. ( 85fed6 , b/181042665 )
بهروزرسانیهای وابستگی
- Lifecycle Runtime Compose now depends on Compose Runtime
1.7.1
نسخه ۲.۸.۵
۴ سپتامبر ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.5 is released. Version 2.8.5 contains these commits .
رفع اشکالات
- Update the
androidx.lifecycle.ReportFragmentProGuard rules to allow obfuscation . ( ff898e1 )
External Contribution
-
SavedStateHandle.saveableextension delegate now supports nullable values. Thanks Roman Kalukiewicz for the contribution. ( 0d78ea6 )
نسخه ۲.۸.۴
۲۴ ژوئیه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.4 is released. Version 2.8.4 contains these commits .
رفع اشکالات
-
LiveData.asFlow()now correctly handles cases where the returned Flow is immediately completed after receiving a value already set on theLiveData(for example, when usingtake(1)). ( I9c566 ) -
Lifecycle*Effectcompletion is now idempotent (ie, if theonStopOrDisposewas called because of the Lifecycle being stopped, it won't be called a second time upon disposal unless the Lifecycle goes back up toSTARTEDagain). ( I5f607 , b/352364595 )
Version 2.8.3
۱ ژوئیه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.3 is released. Version 2.8.3 contains these commits .
رفع اشکالات
- Fixed an issue with Lifecycle 2.8's backward compatibility with Compose 1.6.0 and lower when using code shrinking. ( aosp/3133056 , b/346808608 )
نسخه ۲.۸.۲
۱۲ ژوئن ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.2 is released. Version 2.8.2 contains these commits .
رفع اشکالات
- Fixed
CompositionLocal LocalLifecycleOwner not presenterrors when using Lifecycle 2.8.X with Compose 1.6.X or earlier - you can now use Lifecycle 2.8.2 with any version of Compose without any workarounds required. ( aosp/3105647 , b/336842920 ) -
ViewModelProviderwill no longer crash when mixing previous versions ofcompileOnlyLifecycle dependencies with versions 2.8+, fixing issues with libraries such as LeakCanary. ( I80383 , b/341792251 )
نسخه ۲.۸.۱
۲۹ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.1 is released. Version 2.8.1 contains these commits .
رفع اشکالات
-
lifecycle-viewmodel-composenow only has a common dependency oncompose-runtime, removing its common dependency oncompose-ui. The Android artifact retains itscompose-uifor compatibility. ( aosp/3079334 , b/339562627 ) -
ViewModel'ssaveableintegration using property delegates now uses the class name as part of the auto-generated key, avoiding conflicts if multiple classes use the sameSavedStateHandle. ( aosp/3063463 )
نسخه ۲.۸.۰
۱۴ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0 is released. Version 2.8.0 contains these commits .
Important changes since 2.7.0
-
LocalLifecycleOwnerhas been moved from Compose UI tolifecycle-runtime-composeso that its Compose-based helper APIs can be used outside of Compose UI. - The
lifecycle-runtime-composeartifact now contains thedropUnlessResumedanddropUnlessStartedAPIs which allow you to drop click or other events that occur even after theLifecycleOwnerhas dropped below the givenLifecycle.State. For example, this can be used with Navigation Compose to avoid handling click events after a transition to another screen has already begun:onClick: () -> Unit = dropUnlessResumed { navController.navigate(NEW_SCREEN) } ViewModel.viewModelScopeis now an overridable constructor parameter, allowing you to inject your own dispatcher andSupervisorJob()or to override the default by using thebackgroundScopeavailable withinrunTest. ( I2817c , b/264598574 )class MyViewModel( // Make Dispatchers.Main the default, rather than Dispatchers.Main.immediate viewModelScope: CoroutineScope = Dispatchers.Main + SupervisorJob() ) : ViewModel(viewModelScope) { // Use viewModelScope as before, without any code changes } // Allows overriding the viewModelScope in a test fun Test() = runTest { val viewModel = MyViewModel(backgroundScope) }ViewModelhas been rewritten in Kotlin and now usesAutoClosableinstead ofCloseable. It now supports addingAutoCloseableobjects with akeythat allows retrieving them viagetCloseable().Calling
LifecycleStartEffectandLifecycleResumeEffectwithout a key is now an error, following the same convention as theDisposableEffectAPI that these APIs mirror.Deprecated
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)in favor ofLiveData.toPublisher(lifecycleOwner).The
lifecycle-livedata-core-ktxkotlin extensions have now been moved to thelifecycle-livedata-coremodule.The
NullSafeMutableLiveDatahas been refactored to avoid many false positives.
Lifecycle Kotlin Multiplatform Compatibility
The core Lifecycle APIs in Lifecycle , LifecycleOwner , LifecycleObserver , Lifecycle.State , Lifecycle.Event , and LifecycleRegistry are now shipped in artifacts compatible with Kotlin Multiplatform.
Artifacts impacted:
-
lifecycle-commonmoves most APIs tocommonand supports jvm and iOS in addition to Android. -
lifecycle-runtimemoves most APIs tocommonand supports jvm and iOS in addition to Android. -
lifecycle-runtime-ktxis now empty, with all APIs being moved intolifecycle-runtime. -
lifecycle-runtime-composemoves all APIs tocommonand ships an Android artifact, matching the multiplatform support ofandroidx.compose.
ViewModel Kotlin Multiplatform Compatibility
The lifecycle-viewmodel artifact and APIs like ViewModel , ViewModelStore , ViewModelStoreOwner , and ViewModelProvider are now shipped in artifacts compatible with Kotlin Multiplatform.
To accommodate this change, methods such as those on ViewModelProvider that took a java.lang.Class<T> now have an equivalent method that takes a kotlin.reflect.KClass<T> .
Binary compatibility on Android has been maintained, but there are a few notable changes when comparing the Android API surface to the common API surface:
- Constructing a
ViewModelProviderinstance is now done through theViewModelProvider.create()methods rather than directly calling its constructor. -
ViewModelProvider.NewInstanceFactoryandViewModelProvider.AndroidViewModelFactoryare only available on Android.- Custom Factories are recommended to extend from
ViewModelProvider.Factoryand use thecreatemethod that takes aCreationExtrasor use theviewModelFactoryKotlin DSL.
- Custom Factories are recommended to extend from
- Using
ViewModelProviderwithout a custom factory on non-JVM platforms will result in anUnsupportedOperationException. On JVM platforms, compatibility is preserved by using the no-args ViewModel constructor if a custom factory is not provided. -
viewModelScopewill fallback to anEmptyCoroutineContextin platforms whereDispatchers.Mainis not available (eg, Linux).
Artifacts impacted:
-
lifecycle-viewmodelmoves most APIs tocommonand supports jvm and iOS in addition to Android. -
lifecycle-viewmodel-ktxis now empty, with all APIs being moved intolifecycle-viewmodel. -
lifecycle-viewmodel-composemoves all APIs tocommonand ships an Android artifact, matching the multiplatform support ofandroidx.compose.
تغییرات رفتاری
-
InitializerViewModelFactory(includingviewModelFactorybuilder function) will now throw anIllegalArgumentExceptionif ainitializerwith the sameclazz: KClass<VM : ViewModel>has already been added. ( Ic3a36 )
مشکلات شناخته شده
-
lifecycle-*:2.8.0requires a minimum Compose version of 1.7.0-alpha05 ( b/336842920 ).
Version 2.8.0-rc01
۱ مه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-rc01 is released. Version 2.8.0-rc01 contains these commits .
رفع اشکالات
- Fixed an issue where the Baseline Profile for
lifecycle-commonclasses was not properly packaged. These are now packaged in thelifecycle-runtimeAAR. ( aosp/3038274 , b/322382422 ) - Fixed an unintentional ordering change in how
AutoCloseableinstances attached to a ViewModel are cleared - the previous order ofaddCloseable(String, AutoCloseable), thenaddClosable(AutoCloseable), thenonCleared()has been restored. ( aosp/3041632 ) - Improve the default creation behavior for
viewModelScopefor native and JVM Desktop environments. ( aosp/3039221 )
External Contribution
- Thanks Victor Kropp for improving the checking for the main thread on JVM Desktop. ( aosp/3037116 )
Version 2.8.0-beta01
۱۷ آوریل ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-beta01 is released. Version 2.8.0-beta01 contains these commits .
ویژگیهای جدید
- The
lifecycle-runtime-composeartifact is now compatible with Kotlin Multiplatform, moving its code tocommonand ships an Android artifact, matching the multiplatform support forandroidx.compose. ( If7a71 , I4f4a0 , b/331769623 )
Version 2.8.0-alpha04
۳ آوریل ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha04 is released. Version 2.8.0-alpha04 contains these commits .
ویژگیهای جدید
- The
lifecycle-viewmodel-composeartifact is now compatible with Kotlin Multiplatform, moving its code tocommonand ships an Android artifact, matching the multiplatform support ofandroidx.compose. The accommodate this change, the ComposableviewModelmethod now accepts aKClassin addition to ajava.lang.Class. ( b/330323282 )
رفع اشکالات
- The
NullSafeMutableLiveDatahas been refactored to avoid many false positives. ( I2d8c1 , Iafb18 , I03463 , I7ecef )
بهروزرسانی وابستگی
- The
lifecycle-viewmodel-composeartifact now depends on Compose 1.6.0. - Lifecycle now depends on Profile Installer 1.3.1 .
Version 2.8.0-alpha03
۲۰ مارس ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha03 is released. Version 2.8.0-alpha03 contains these commits .
ویژگیهای جدید
ViewModel.viewModelScopeis now an overridable constructor parameter, allowing you to inject your own dispatcher andSupervisorJob()or to override the default by using thebackgroundScopeavailable withinrunTest. ( I2817c , b/264598574 )class MyViewModel( // Make Dispatchers.Main the default, rather than Dispatchers.Main.immediate viewModelScope: CoroutineScope = Dispatchers.Main + SupervisorJob() ) : ViewModel(viewModelScope) { // Use viewModelScope as before, without any code changes } // Allows overriding the viewModelScope in a test fun Test() = runTest { val viewModel = MyViewModel(backgroundScope) }
Kotlin Multiplatform Compatibility
The lifecycle-viewmodel artifact and APIs like ViewModel , ViewModelStore , ViewModelStoreOwner , and ViewModelProvider are now shipped in artifacts compatible with Kotlin Multiplatform. ( b/214568825 )
To accommodate this change, methods such as those on ViewModelProvider that took a java.lang.Class<T> now have an equivalent method that takes a kotlin.reflect.KClass<T> .
Binary compatibility on Android has been maintained, but there are a few notable changes when comparing the Android API surface to the common API surface:
- Constructing a
ViewModelProviderinstance is now done through theViewModelProvider.create()methods rather than directly calling its constructor. -
ViewModelProvider.NewInstanceFactoryandViewModelProvider.AndroidViewModelFactoryare only available on Android.- Custom Factories are recommended to extend from
ViewModelProvider.Factoryand use thecreatemethod that takes aCreationExtrasor use theviewModelFactoryKotlin DSL.
- Custom Factories are recommended to extend from
- Using
ViewModelProviderwithout a custom factory on non-JVM platforms will result in anUnsupportedOperationException. On JVM platforms, compatibility is preserved by using the no-args ViewModel constructor if a custom factory is not provided. -
viewModelScopewill fallback to anEmptyCoroutineContextin platforms whereDispatchers.Mainis not available (eg, Linux).
تغییرات رفتاری
-
InitializerViewModelFactory(includingviewModelFactorybuilder function) will now throw anIllegalArgumentExceptionif ainitializerwith the sameclazz: KClass<VM : ViewModel>has already been added. ( Ic3a36 )
رفع اشکالات
-
ViewModel.getCloseablenow handles duplicated keys: if thekeyalready has anAutoCloseableresource associated with it, the old resource will be replaced and closed immediately. ( Ibeb67 ) - Accessing the
viewModelScopeof aViewModelis now thread safe. ( If4766 , b/322407038 )
External Contribution
-
LocalLifecycleOwnermoved from Compose UI to lifecycle-runtime-compose so that its Compose-based helper APIs can be used outside of Compose UI. Thanks Jake Wharton for the contribution. ( I6c41b , b/328263448 )
Version 2.8.0-alpha02
۲۱ فوریه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha02 is released. Version 2.8.0-alpha02 contains these commits.
ویژگیهای جدید
- The
dropUnlessResumedanddropUnlessStartedAPIs have been added which allow you to drop click or other events that occur even after theLifecycleOwnerhas dropped below the givenLifecycle.State. For example, this can be used with Navigation Compose to avoid handling click events after a transition to another screen has already begun:onClick: () -> Unit = dropUnlessResumed { navController.navigate(NEW_SCREEN) }( Icba83 , b/317230685 )
تبدیلهای کاتلین
-
ViewModelis now written in Kotlin ( I16f26 , b/214568825 ) - The
lifecycle-viewmodel-ktxkotlin extensions have now been moved to the base lifecycle module. ( Id787b , b/274800183 ) - The
lifecycle-runtime-ktxkotlin extensions have now been moved to the base lifecycle module. ( Ic3686 , b/274800183 ) - The
lifecycle-livedata-core-ktxkotlin extensions have now been moved to the base lifecycle module. ( I54a3d , b/274800183 )
Kotlin Multiplatform Compatibility
- The core Lifecycle APIs in
Lifecycle,LifecycleOwner,LifecycleObserver,Lifecycle.State,Lifecycle.Event, andLifecycleRegistryare now shipped in artifacts compatible with Kotlin Multiplatform. ( b/317249252 )
تغییرات API
- Calling
LifecycleStartEffectandLifecycleResumeEffectwithout a key is now an error, following the same convention as theDisposableEffectAPI that these APIs mirror. ( Ib0e0c , b/323518079 ) -
ViewModelnow usesAutoCloseableinstead ofCloseable. That is a backward compatible change. ( I27f8e , b/214568825 ) - Deprecated
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)in favor ofLiveData.toPublisher(lifecycleOwner). ( Iabe29 , b/262623005 )
External Contribution
- Thanks Ivan Matkov from Jetbrains for helping move Lifecycle to Kotlin Multiplatform. ( aosp/2926690 , I0c5ac , If445d )
Version 2.8.0-alpha01
۲۴ ژانویه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.8.0-alpha01 is released. Version 2.8.0-alpha01 contains these commits.
ویژگیهای جدید
-
ViewModelnow supports addingCloseableobjects with akeythat allows retrieving them viagetCloseable(). ( I3cf63 )
Version 2.7
Version 2.7.0
۱۰ ژانویه ۲۰۲۴
androidx.lifecycle:lifecycle-*:2.7.0 is released. Version 2.7.0 contains these commits.
Important changes since 2.6.0
-
TestLifecycleOwnernow includes a suspending functionsetCurrentState()which ensures that the state change and allLifecycleObservercallbacks are completed before returning. Notably, unlike setting thecurrentStateproperty directly, this does not userunBlocking, making it safe to use within a coroutine such as one provided byrunTest. - The
LiveDataextensions ofmapandswitchMapnow mirror the behavior ofdistinctUntilChanged- if theLiveDatahas avalueset, themap/switchMapfunction will be immediately called to populate thevalueof the returnedLiveData. This ensures that the initial value will be set as part of the first composition (when used withobserveAsState()), but does not change the observation behavior - updates values from the sourceLiveDatawill still only apply once you start observing theLiveData. - This release fixes an issue where
SavedStateHandlewould not properly restore customParcelableclasses after process death and recreation. Due to type information that is lost by the Android framework, arrays of custom Parcelables require additional work (manually creating a typed array of the right type) and the documentation onget,getLiveData, andgetStateFlownow specifically calls this limitation out. - The proguard keep rules associated with
LifecycleObserverhave been removed. This means that proguarded code that wishes to use APIs via reflection (such as using the long since deprecated@OnLifecycleEventannotation) will need to provide their own keep rules for their specific use case.
Lifecycle Event Observability
- As an alternative to using a
LifecycleEventObserver, you can now observe aFlowofLifecycle.Eventvia theLifecycle.asFlow()extension method. - Jetpack Compose users can now use
LifecycleEventEffectto run Compose side effects based onLifecycle.Event.
@Composable
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
viewModel.refreshData()
}
// …
}
- Jetpack Compose users can use
LifecycleStartEffectandLifecycleResumeEffectto handle pairs of events - started to stopped and resumed to paused, respectively. This API mirrors the one found inDisposableEffectand is suitable for cases where the change being made when the state is going up needs to be reversed when going back down.
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleStartEffect(viewModel) {
val timeTracking = viewModel.startTrackingTimeOnScreen()
onStopOrDispose {
timeTracking.stopTrackingTimeOnScreen()
}
}
// …
}
See Run code on lifecycle events for more information.
Lifecycle State Observability
- The current
Lifecycle.Statecan now be observed via theLifecycle.currentStateFlowproperty, which returns aStateFlowwhere thevalueis the currentLifecycle.State. - Jetpack Compose users can use the
Lifecycle.currentStateAsState()extension to directly exposeLifecycle.Stateas ComposeState. This is equivalent (and a shorter alternative) tolifecycle.currentStateFlow.collectAsState().
See Collect lifecycle state with flows for more information.
Version 2.7.0-rc02
۱۳ دسامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-rc02 is released. Version 2.7.0-rc02 contains these commits.
رفع اشکالات
- Fixed an issue where
SavedStateHandlewould not properly restore customParcelableclasses after process death and recreation. Due to type information that is lost by the Android framework, arrays of custom Parcelables require additional work (manually creating a typed array of the right type) and the documentation onget,getLiveData, andgetStateFlownow specifically calls this limitation out. ( I0b55a )
Version 2.7.0-rc01
۱۵ نوامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-rc01 is released. Version 2.7.0-rc01 contains these commits.
رفع اشکالات
-
LifecycleStartEffectandLifecycleResumeEffectnow correctly dispose and recreate the effect block if theLifecycleOwneris changed. ( Ia25c6 )
Version 2.7.0-beta01
۱ نوامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-beta01 is released with no changes. Version 2.7.0-beta01 contains these commits.
- A beta version bump, no major changes to this release version.
Version 2.7.0-alpha03
۱۸ اکتبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha03 is released. Version 2.7.0-alpha03 contains these commits.
ویژگیهای جدید
-
lifecycle-runtime-testingnow contains a new Lint check to avoid setting theLifecycle.Stateof theTestLifecycleOwnerby using thecurrentStatefield when inside of a coroutine. The Lint check now suggests the suspendingsetCurrentStatewhich allows setting theLifecycle.Statewithout blocking. ( Icf728 , b/297880630 )
رفع اشکالات
- Fixed an issue with
LiveData.switchMapwhere returning the sameLiveDatainstance both on the initial call and a subsequent call would prevent theLiveDatainstance from being added as a source. ( Ibedcba7 )
Version 2.7.0-alpha02
۶ سپتامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha02 is released. Version 2.7.0-alpha02 contains these commits.
ویژگیهای جدید
-
TestLifecycleOwnernow includes the suspending functionsetCurrentState()to give users the option of usingTestLifecycleOwnerfrom within a coroutine such as one provided byrunTest. ( I329de , b/259344129 )
تغییرات API
- All files from the
lifecycle-livedata-ktxmodules have been moved into the mainlifecycle-livedatamodule. ( I10c6f , b/274800183 )
تغییرات رفتاری
- The
LiveData.map()andLiveData.switchMap()extensions now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it, ensuring that using the resulting LiveData in Jetpack Compose has the right state on the initial composition. ( I91d2b , b/269479952 ) -
ViewModel'saddCloseable()now immediately closes theCloseableif theViewModelhas already received a call toonCleared(). ( I4712e , b/280294730 )
رفع اشکالات
- From Lifecycle
2.6.2: Fixed an issue whereSavedStateHandlewould not correctly be restored after process death if the state was restored,save()was called without actually saving the state in the parentSavedStateRegistry, and then the state was restored again. This fixes the interaction betweenrememberSaveableand Navigation Compose'sNavHost. ( aosp/2729289 )
Version 2.7.0-alpha01
۲۶ ژوئیه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.7.0-alpha01 is released. Version 2.7.0-alpha01 contains these commits.
تغییرات API
-
Lifecycle.Stateis now Compose-observable viaLifecycle.currentStateFlow, which returns aStateFlowwhere thevalueis the currentLifecycle.State. ( Ib212d , b/209684871 ) -
Lifecycle.Events can now able to be observed as aFlowwithLifecycle.asFlow().( If2c0f , b/176311030 ) -
LifecycleResumeEffectAPI has been added to run ComposeSideEffects based on bothLifecycle.Event.ON_RESUMEandLifecycle.Event.ON_PAUSEevent callbacks. ( I60386 , b/235529345 ) -
LifecycleStartEffectAPI has been added to run ComposeSideEffects based onLifecycle.Event.ON_STARTandLifecycle.Event.ON_STOPevent callbacks. ( I5a8d1 , b/235529345 ) -
LifecycleEventEffectAPI has been added to run ComposeSideEffects based onLifecycle.Event. ( Ic9794 , b/235529345 ) -
Lifecycle.collectAsState()extension has been added to directly exposeLifecycle.Stateas ComposeState. This is equivalent (and a shorter alternative) tolifecycle.currentStateFlow.collectAsState(). ( I11015 , b/235529345 )
رفع اشکالات
- The
LiveData.distinctUntilChanged()extension now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it. This does not change the observation behavior - updated values from the sourceLiveDatawill still only apply once you start observing theLiveDatareturned fromdistinctUntilChanged(). ( Ib482f ) - The proguard keep rules associated with
LifecycleObserverhave been removed. This means that proguarded code that wishes to use APIs via reflection will need to provide their own keep rules for their specific use case. ( Ia12fd )
نسخه ۲.۶
نسخه ۲.۶.۲
۶ سپتامبر ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.2 is released. Version 2.6.2 contains these commits.
رفع اشکالات
- Fixed an issue where
SavedStateHandlewould not correctly be restored after process death if the state was restored,save()was called without actually saving the state in the parentSavedStateRegistry, and then the state was restored again. This fixes the interaction betweenrememberSaveableand Navigation Compose'sNavHost. ( aosp/2729289 )
Version 2.6.1
۲۲ مارس ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.1 is released. Version 2.6.1 contains these commits.
بهروزرسانیهای وابستگی
-
lifecycle-viewmodel-savedstatenow depends on SavedState1.2.1. ( cd7251 ) - Lifecycle now depends on ProfileInstaller
1.3.0. ( f9d30b )
نسخه ۲.۶.۰
۸ مارس ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0 is released. Version 2.6.0 contains these commits.
Important changes since 2.5.0
-
LiveDatanow includes a newisInitializedproperty that indicates whether an explicit value has ever been set on theLiveData, allowing you to distinguish betweenliveData.valuereturningnullbecause no value has ever been set or an explicitnullvalue. -
MediatorLiveDatanow includes a constructor to set an initial value. - Added a new extension on
StateFlowandFlowofcollectAsStateWithLifecycle()that collect from flows and represents its latest value as Compose State in a lifecycle-aware manner. -
Lifecycle.launchWhenXmethods andLifecycle.whenXmethods have been deprecated as the use of a pausing dispatcher can lead to wasted resources in some cases. It is recommended to useLifecycle.repeatOnLifecycle. For more information about one-time suspending work, please see this explanation on why this is inherently unsafe. - Kotlin Conversion - A large number of Lifecycle classes have been converted to Kotlin. All converted classes still retain their binary compatibility with previous versions. The following classes have source incompatible changes for classes written in Kotlin:
ViewTreeLifecycleOwner,LiveDataReactiveStreams,HasDefaultViewModelProviderFactory,ViewTreeViewModelStoreOwner,Transformations,ViewModelStoreOwner,LifecycleOwner
The table below provides the source conversions for the new version of lifecycle.
| Lifecycle 2.5 | Lifecycle 2.5 (KTX) | Lifecycle 2.6 |
|---|---|---|
Transformations.switchMap(liveData) {...} | liveData.switchMap {...} | liveData.switchMap {...} |
Transformations.map(liveData) {...} | liveData.map {...} | liveData.map {...} |
Transformations.distinctUntilChanged(liveData) {...} | liveData.distinctUntilChanged{...} | liveData.distinctUntilChanged{...} |
LiveDataReactiveStreams.fromPublisher(publisher) | publisher.toLiveData() | publisher.toLiveData() |
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData) | liveData.toPublisher(lifecycleOwner) | liveData.toPublisher(lifecycleOwner) |
override fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory = factory | override fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory = factory | override val defaultViewModelProviderFactory = factory |
override fun getDefaultViewModelCreationExtras(): CreationExtras = extras | override fun getDefaultViewModelCreationExtras(): CreationExtras = extras | override val defaultViewModelProviderCreationExtras = extras |
ViewTreeLifecycleOwner.set(view, owner) | ViewTreeLifecycleOwner.set(view, owner) | view.setViewTreeLifecycleOwner(owner) |
ViewTreeLifecycleOwner.get(view) | view.findViewTreeLifecycleOwner() | view.findViewTreeLifecycleOwner() |
override fun getViewModelStore(): ViewModelStore = store | override fun getViewModelStore(): ViewModelStore = store | override val viewModelStore: ViewModelStore = store |
override fun getLifecycle(): Lifecycle = registry | override fun getLifecycle(): Lifecycle = registry | override val lifecycle: Lifecycle get() = registry |
- The nullability of the
onChangedmethod of aObservercreated in Kotlin now matches the nullability of the generic type. If you wantObserver.onChanged()to accept a nullable type, you must instantiate theObserverwith a nullable type. - These classes were also converted to Kotlin, but remain source compatible:
DefaultLifecycleObserver,LifecycleEventObserver,Lifecycle,LifecycleRegistry,LifecycleObserver,ViewModelStore,AndroidViewModel,AbstractSavedStateViewModelFactory,LifecycleService,ServiceLifecycleDispatcher, andProcessLifecycleOwner
Version 2.6.0-rc01
۲۲ فوریه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-rc01 is released. Version 2.6.0-rc01 contains these commits.
رفع اشکالات
- The
LiveData.distinctUntilChanged()extension now sets thevalueof the returnedLiveDataif the previousLiveDatahas had a value set on it. This does not change the observation behavior - updated values from the sourceLiveDatawill still only apply once you start observing theLiveDatareturned fromdistinctUntilChanged(). ( Ib482f )
Version 2.6.0-beta01
۸ فوریه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-beta01 is released. Version 2.6.0-beta01 contains these commits.
تبدیلهای کاتلین
-
LifecycleOwneris now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thelifecycleproperty rather than implementing the previousgetLifecycle()function. ( I75b4b , b/240298691 ) -
ViewModelStoreOwneris now in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override theviewModelStoreproperty rather than implementing the previousgetViewModelStore()function. ( I86409 , b/240298691 ) - The Kotlin extension on
LifecycleOwnerthat provides thelifecycleScopefield has been moved to thelifecycle-commonartifact fromlifecycle-runtime-ktx. ( I41d78 , b/240298691 ) - The Kotlin extension on
Lifecyclethat provides thecoroutineScopefield has been moved to thelifecycle-commonartifact fromlifecycle-runtime-ktx. ( Iabb91 , b/240298691 )
Version 2.6.0-alpha05
۲۵ ژانویه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-alpha05 is released. Version 2.6.0-alpha05 contains these commits.
تبدیلهای کاتلین
-
Transformationsis now written in Kotlin. This is a source incompatible change for those classes written in Kotlin that were directly using syntax such asTransformations.map- Kotlin code must now use the Kotlin extension method syntax that was previously only available when usinglifecycle-livedata-ktx. When using the Java programming language, the versions of these methods that take anandroidx.arch.core.util.Functionmethod are deprecated and replaced with the versions that take a KotlinFunction1. This change maintains binary compatibility. ( I8e14f ) -
ViewTreeViewModelStoreOwneris now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.lifecycle.setViewTreeViewModelStoreOwnerandandroidx.lifecycle.findViewTreeViewModelStoreOwnerto set and find a previously set owner. This is binary compatible and remains source compatible for implementations written in the Java programming language. ( Ia06d8 , Ib22d8 , b/240298691 ) - The
HasDefaultViewModelProviderFactoryinterface is now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thedefaultViewModelProviderFactoryanddefaultViewModelCreationExtrasproperties rather than implementing the previous corresponding functions. ( Iaed9c , b/240298691 ) -
Observeris now written in Kotlin. ItsonChanged()method now uses the namevaluefor its parameter. ( Iffef2 , I4995e , b/240298691 ) -
AndroidViewModel,AbstractSavedStateViewModelFactory,LifecycleService,ServiceLifecycleDispatcher, andProcessLifecycleOwnerare now written in Kotlin ( I2e771 , Ibae40 , I160d7 , I08884 , I1cda7 , b/240298691 )
Version 2.6.0-alpha04
۱۱ ژانویه ۲۰۲۳
androidx.lifecycle:lifecycle-*:2.6.0-alpha04 is released. Version 2.6.0-alpha04 contains these commits.
ویژگیهای جدید
-
LiveDatanow includes a newisInitializedproperty that indicates whether an explicit value has ever been set on theLiveData, allowing you to distinguish betweenliveData.valuereturningnullbecause no value has ever been set or an explicitnullvalue. ( Ibd018 )
تغییرات API
- The
collectAsStateWithLifecycle()APIs oflifecycle-runtime-composeare no longer in experimental status. ( I09d42 , b/258835424 ) -
Lifecycle.launchWhenXmethods andLifecycle.whenXmethods have been deprecated as the use of a pausing dispatcher can lead to wasted resources in some cases. It is recommended to useLifecycle.repeatOnLifecycle. ( Iafc54 , b/248302832 )
تبدیلهای کاتلین
-
ViewTreeLifecycleOwneris now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now directly import and use the Kotlin extension methods onViewofandroidx.lifecycle.setViewTreeLifecycleOwnerandandroidx.lifecycle.findViewTreeLifecycleOwnerto set and find a previously set owner. This replaces the previous Kotlin extension inlifecycle-runtime-ktx. This is binary compatible and remains source compatible for implementations written in the Java programming language. ( I8a77a , I5234e , b/240298691 ) -
LiveDataReactiveStreamsis now written in Kotlin. The Kotlin extensions previously inlifecycle-reactivestreams-ktxhave been moved into thelifecycle-reactivestreamsmodule and have become the primary surface for code written in Kotlin. This is a source incompatible change for code written in Kotlin if you were not already using the Kotlin extension method APIs. ( I2b1b9 , I95d22 , b/240298691 ) -
DefaultLifecycleObserver,LifecycleEventObserver,Lifecycle,LifecycleRegistry,LifecycleObserver, andViewModelStoreare now written in Kotlin ( Iadffd , ( I60034 , I8c52c , I9593d , I01fe1 , I59a23 , b/240298691 )
رفع اشکالات
-
SavedStateHandleno longer crashes with aClassCastExceptionwhen callingget()with the incorrect class type. ( I6ae7c )
Version 2.6.0-alpha03
۲۴ اکتبر ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha03 is released. Version 2.6.0-alpha03 contains these commits.
رفع اشکالات
- Fixed an issue with constraints between different Lifecycle modules not working as intended. ( I18d0d , b/249686765 )
- Errors thrown by
LifecycleRegistry.moveToState()now include a more helpful error messaging that informs developers of the component causing the error. ( Idf4b2 , b/244910446 )
Version 2.6.0-alpha02
۷ سپتامبر ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha02 is released. Version 2.6.0-alpha02 contains these commits.
تغییرات API
-
MediatorLiveDatanow includes a constructor to set an initial value. ( Ib6cc5 , b/151244085 )
رفع اشکالات
-
Lifecycleartifacts now include constraints that ensure that all inter-dependent Lifecycle artifacts use the same version, automatically upgrading other dependencies when one is upgraded. b/242871265 -
FlowLiveData.asFlow()now creates acallbackFlowrather than using its ownChannelimplementation to ensure thread-safety and context preservation. ( I4a8b2 , b/200596935 ) -
FlowLiveData'sasLiveDatafunction will now preserve the initial value of aStateFlowwhen creating the newLiveDataobject. ( I3f530 , b/157380488 ) - From Lifecycle
2.5.1: Custom implementations ofAndroidViewModelFactorynow correctly calls thecreate(modelClass)function when using the stateful constructor withLifecycle2.4+ ( I5b315 , b/238011621 )
Version 2.6.0-alpha01
۲۹ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.6.0-alpha01 is released. Version 2.6.0-alpha01 contains these commits.
ویژگیهای جدید
- Added a new extension on
StateFlowandFlowofcollectAsStateWithLifecyclethat collect from flows and represents its latest value as Compose State in a lifecycle-aware manner. The flow is collected and the new emission is set to the State's value when the lifecycle is at least in a certainLifecycle.State. When the lifecycle falls below thatLifecycle.State, the flow collection stops and the State's value is not updated. ( I1856e , b/230557927 )
نسخه ۲.۵
نسخه ۲.۵.۱
۲۷ ژوئیه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.1 is released. Version 2.5.1 contains these commits.
رفع اشکالات
- Custom implementations of
AndroidViewModelFactorynow correctly call thecreate(modelClass)function when using the statefulAndroidViewModelFactoryconstructor withLifecycle2.4+. ( I5b315 , b/238011621 )
Version 2.5.0
۲۹ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0 is released. Version 2.5.0 contains these commits.
Important changes since 2.4.0
SavedStateHandlenow offers agetStateFlow()API that returns a KotlinStateFlowfor monitoring value changes as an alternative to usingLiveData.ViewModel CreationExtras - when writing a custom
ViewModelProvider.Factory, it is no longer required to extendAndroidViewModelFactoryorAbstractSavedStateViewModelFactoryto gain access to anApplicationorSavedStateHandle, respectively. Instead, these fields are provided to everyViewModelProvider.Factorysubclass asCreationExtrasvia the new overload ofcreate:create(Class<T>, CreationExtras). These extras are provided automatically by your Activity or Fragment when using Activity1.5.0and Fragment1.5.0, respectively.class CustomFactory : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T { return when (modelClass) { HomeViewModel::class -> { // Get the Application object from extras val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) // Pass it directly to HomeViewModel HomeViewModel(application) } DetailViewModel::class -> { // Create a SavedStateHandle for this ViewModel from extras val savedStateHandle = extras.createSavedStateHandle() DetailViewModel(savedStateHandle) } else -> throw IllegalArgumentException("Unknown class $modelClass") } as T } }lifecycle-viewmodelnow provides aviewModelFactoryKotlin DSL that allows you define yourViewModelProvider.Factoryin terms of one or more lambda initializers, one for each particularViewModelclass your custom factory supports, usingCreationExtrasas the primary data source.val customFactory = viewModelFactory { // The return type of the lambda automatically sets what class this lambda handles initializer { // Get the Application object from extras provided to the lambda val application = checkNotNull(get(ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY)) HomeViewModel(application) } initializer { val savedStateHandle = createSavedStateHandle() DetailViewModel(savedStateHandle) } }lifecycle-viewmodel-composenow offers aviewModel()API that takes a lambda factory for creating aViewModelinstance without requiring the creation of a customViewModelProvider.Factory.// Within a @Composable, you can now skip writing a custom Factory // and instead write a lambda to do the initialization of your ViewModel val detailViewModel = viewModel { // This lambda is only called the first time the ViewModel is created // and all CreationExtras are available inside the lambda val savedStateHandle = createSavedStateHandle() DetailViewModel(savedStateHandle) }SavedStateHandle Compose Saver Integration - the
lifecycle-viewmodel-composeartifact now contains new experimental APIs inSavedStateHandle.saveablethat allowrememberSaveablelike behavior backed by theSavedStateHandleof a `ViewModel.class ListScreenViewModel(handle: SavedStateHandle): ViewModel() { // This value survives both configuration changes and process death and recreation val editMode by handle.saveable { mutableStateOf(false) } }Added an
addCloseable()API and a new constructor overload that allow you to add one or moreCloseableobjects to theViewModelthat will be closed when theViewModelis cleared without requiring any manual work inonCleared().For instance, to create a coroutine scope that you can inject into a ViewModel, but control via testing, you can create a
CoroutineScopethat implementsCloseable:class CloseableCoroutineScope( context: CoroutineContext = SupervisorJob() + Dispatchers.Main.immediate ) : Closeable, CoroutineScope { override val coroutineContext: CoroutineContext = context override fun close() { coroutineContext.cancel() } }Which can then be used in your
ViewModelconstructor while maintaining the same lifetime asviewModelScope:class TestScopeViewModel( val customScope: CloseableCoroutineScope = CloseableCoroutineScope() ) : ViewModel(customScope) { // You can now use customScope in the same way as viewModelScope }
Behavior changes
- Attempting to move the
Lifecycle.StatefromINITIALIZEDtoDESTROYEDwill now always throw anIllegalStateExceptionregardless of whether theLifecyclehas an attached observer. -
LifecycleRegistrywill now clear their observers when they reach theDESTROYEDstate.
Version 2.5.0-rc02
۱۵ ژوئن ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-rc02 is released. Version 2.5.0-rc02 contains these commits.
رفع اشکالات
-
ViewModelProviderwill no longer crash when mixing previous versions of compileOnly Lifecycle dependencies with versions 2.5+. ( I81a66 , b/230454566 )
Version 2.5.0-rc01
۱۱ مه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-rc01 is released. Version 2.5.0-rc01 contains these commits.
رفع اشکالات
-
MediatorLiveData.addSource()now throws aNullPointerExceptionwhen passed anullsource instead of propagating thenullsource to observers.( Ibd0fb , b/123085232 )
Version 2.5.0-beta01
۲۰ آوریل ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-beta01 is released. Version 2.5.0-beta01 contains these commits.
تغییرات API
- Added
SavedStateHandle.saveableproperty delegates to use property names as keys for persisting state into theSavedStateHandle( I8bb86 , b/225014345 )
رفع اشکالات
- Fixed an issue where nesting one
NavHostwithin anotherNavHostin a non-primary bottom navigation tab would lead to anIllegalStateExceptionwhen using multiple back stacks. ( I11bd5 , b/228865698 )
Version 2.5.0-alpha06
۶ آوریل ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha06 is released. Version 2.5.0-alpha06 contains these commits.
ویژگیهای جدید
- Add experimental
MutableStateoverload toSavedStateHandle.saveablefor parity withrememberSaveable( I38cfe , b/224565154 )
تغییرات API
-
CreationExtrasis now abstract instead of sealed. ( Ib8a7a )
رفع اشکالات
- Fixed an
IllegalStateException: Already attached to lifecycleOwnererror caused bySavedStateHandleController. ( I7ea47 , b/215406268 )
Version 2.5.0-alpha05
۲۳ مارس ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha05 is released. Version 2.5.0-alpha05 contains these commits.
ویژگیهای جدید
- The
lifecycle-viewmodel-composemodule now providesSavedStateHandleSaver, an experimental API that ensures values in aSavedStateHandleare integrated correctly with the same saved instance state thatrememberSaveableuses. ( Ia88b7 , b/195689777 )
تغییرات API
- Fixed a compatibility issue with Lifecycle 2.3 and newer Lifecycle versions in Java. ( I52c8a , b/219545060 )
رفع اشکالات
-
SavedStateViewFactorynow supports usingCreationExtraseven when it was initialized with aSavedStateRegistryOwner. If extras are provided, the initialized arguments are ignored. ( I6c43b , b/224844583 )
Version 2.5.0-alpha04
۹ مارس ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha04 is released. Version 2.5.0-alpha04 contains these commits.
تغییرات API
-
SavedStateHandlenow offers agetStateFlow()API that returns a KotlinStateFlowfor monitoring value changes as an alternative to usingLiveData. ( Iad3ab , b/178037961 )
Version 2.5.0-alpha03
۲۳ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha03 is released. Version 2.5.0-alpha03 contains these commits.
ویژگیهای جدید
- Added an
addCloseable()API and a new constructor overload that allow you to add one or moreCloseableobjects to theViewModelthat will be closed when theViewModelis cleared without requiring any manual work inonCleared(). ( I55ea0 ) -
lifecycle-viewmodelnow provides anInitializerViewModelFactorythat allows you to add lambda for handling particularViewModelclasses, usingCreationExtrasas the primary data source. ( If58fc , b/216687549 ) -
lifecycle-viewmodel-composenow offers aviewModel()API that takes a lambda factory for creating aViewModelinstance without requiring the creation of a customViewModelProvider.Factory. ( I97fbb , b/216688927 )
تغییرات API
- You can now create a
ViewModelwithCreationExtrasvialifecycle-viewmodel-compose. ( I08887 , b/216688927 )
Behavior changes
- Attempting to move the
Lifecycle.StatefromINITIALIZEDtoDESTROYEDwill now always throw anIllegalStateExceptionregardless of whether theLifecyclehas an attached observer. ( I7c390 , b/177924329 ) -
LifecycleRegistrywill now clear their observers when they reach theDESTROYEDstate. ( I4f8dd , b/142925860 )
Version 2.5.0-alpha02
۹ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.5.0-alpha02 is released. Version 2.5.0-alpha02 contains these commits.
تغییرات API
-
SavedStateHandleandSavedStateViewModelFactoryhave been converted to Kotlin. This has improved the nullability of the generics in both classes. ( Ib6ce2 , b/216168263 , I9647a , b/177667711 ) - The
LiveDataswitchMapfunction parameter can now have a nullable output. ( I40396 , b/132923666 ) - The
LiveData-ktx extensions are now annotated with@CheckResultto enforce that the result is used when calling these functions. ( Ia0f05 , b/207325134 )
Behavior changes
-
SavedStateHandlenow properly stores the defaultValue when no value for the specified key exists. ( I1c6ce , b/178510877 )
رفع اشکالات
- From Lifecycle
2.4.1: Updatedlifecycle-processto depend on Startup 1.1.1 to ensure that fixes that preventProcessLifecycleInitializerfrom throwing aStartupExceptionare available by default. ( Ib01df , b/216490724 ) - There is now an improved error message when custom
AndroidViewModelclasses have parameters in the wrong order and attempt to create aViewModel. ( I340f7 , b/177667711 ) - You can now create a view model via
CreationExtrasusing theAndroidViewModelFactorywithout setting an application. ( I6ebef , b/217271656 )
Version 2.5.0-alpha01
January 26, 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha01 is released. Version 2.5.0-alpha01 contains these commits.
ViewModel CreationExtras
With this release, we are laying the groundwork for restructuring how a ViewModel is constructed. Instead of a rigid set of subclasses of ViewModelProvider.Factory that each add additional functionality (allowing an Application constructor parameter via AndroidViewModelFactory , allowing a SavedStateHandle constructor parameter via SavedStateViewModelFactory and AbstractSavedStateViewModelFactory , etc.), we are moving to a world of stateless factories that rely on a new concept, CreationExtras . ( Ia7343 , b/188691010 , b/188541057 )
With this change, ViewModelProvider no longer makes direct calls into the previous create(Class<T>) method of ViewModelProvider.Factory . Instead, it calls into a new overload of create : create(Class<T>, CreationExtras) . This means that any direct implementation of the ViewModelProvider.Factory instance now has access to each of these new CreationExtras :
-
ViewModelProvider.NewInstanceFactory.VIEW_MODEL_KEY: thisStringprovides access to the custom key you passed toViewModelProvider.get(). -
ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYprovides access to theApplicationclass. -
SavedStateHandleSupport.SAVED_STATE_REGISTRY_OWNER_KEYprovides access to theSavedStateRegistryOwnerthat is being used to construct this ViewModel. -
SavedStateHandleSupport.VIEW_MODEL_STORE_OWNER_KEYprovides access to theViewModelStoreOwnerthat is being used to construct this ViewModel. -
SavedStateHandleSupport.DEFAULT_ARGS_KEYprovides access to theBundleof arguments that should be used to construct aSavedStateHandle.
These extras are provided by default when using Activity 1.5.0-alpha01 , Fragment 1.5.0-alpha01 , and Navigation 2.5.0-alpha01 . If you use an earlier version of those libraries, your CreationExtras will be empty - all of the existing subclasses of ViewModelProvider.Factory have been rewritten to support both the legacy creation path used by earlier versions of those libraries and the CreationExtras path which will be used going forward.
These CreationExtras allow you to construct a ViewModelProvider.Factory that passes just the information you need to each ViewModel without relying on a strict hierarchy of Factory subclasses:
class CustomFactory : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
return when (modelClass) {
HomeViewModel::class -> {
// Get the Application object from extras
val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY])
// Pass it directly to HomeViewModel
HomeViewModel(application)
}
DetailViewModel::class -> {
// Create a SavedStateHandle for this ViewModel from extras
val savedStateHandle = extras.createSavedStateHandle()
DetailViewModel(savedStateHandle)
}
else -> throw IllegalArgumentException("Unknown class $modelClass")
} as T
}
}
We use the createSavedStateHandle() Kotlin extension function on CreationExtras from SavedStateHandleSupport to construct a SavedStateHandle only for the one ViewModel that needs it. ( Ia6654 , b/188541057 )
Custom CreationExtras can be provided by overriding getDefaultViewModelCreationExtras() in your ComponentActivity or Fragment , thus making them available to your custom ViewModelProvider.Factory as a built in form of assisted injection. These extras will automatically be made available to your custom Factory when used directly with ViewModelProvider or when using the by viewModels() and by activityViewModels() Kotlin property extensions. ( I79f2b , b/207012584 , b/207012585 , b/207012490 )
رفع اشکالات
- Fixed an issue where the default value provided to a
SavedStateHandlewould reappear after process death and recreation, even if it was specifically removed from theSavedStateHandle. As a consequence of this,SavedStateHandlewill no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b )
نسخه ۲.۴
نسخه ۲.۴.۱
۹ فوریه ۲۰۲۲
androidx.lifecycle:lifecycle-*:2.4.1 is released. Version 2.4.1 contains these commits.
رفع اشکالات
- Backported from Lifecycle
2.5.0-alpha01: Fixed an issue where the default value provided to aSavedStateHandlewould re-appear after process death and recreation, even if it was specifically removed from theSavedStateHandle. As a consequence of this,SavedStateHandlewill no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b ) -
lifecycle-processnow depends on Androidx Startup 1.1.1 which fixed a regression in where usingProcessLifecycleInitializerwould cause anStartupException. ( b/216490724 )
نسخه ۲.۴.۰
۲۷ اکتبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0 is released. Version 2.4.0 contains these commits.
Important changes since 2.3.0
-
@OnLifecycleEventwas deprecated.LifecycleEventObserverorDefaultLifecycleObservershould be used instead. -
androidx.lifecycle:lifecycle-viewmodel-composelibrary was added. It providesviewModel()composable andLocalViewModelStoreOwner.- Source-breaking change :
ViewModelProviderhas been rewritten in Kotlin.ViewModelProvider.Factory.createmethod no longer allows nullable generic.
- Source-breaking change :
- New coroutines API were added to
androidx.lifecycle:lifecycle-runtime-ktx: -
Lifecycle.repeatOnLifecycle, API that executes a block of code in a coroutine when the Lifecycle is at least in a certain state. The block will cancel and re-launch as the lifecycle moves in and out of the target state; -
Flow.flowWithLifecycle, API that emits values from the upstream Flow when the lifecycle is at least in a certain state. -
DefaultLifecycleObserverwas moved fromlifecycle.lifecycle-common-java8tolifecycle.lifecycle-common.lifecycle.lifecycle-common-java8doesn't provide anymore any additional functionality on top oflifecycle.lifecycle-common, so dependency on it can be replaced bylifecycle.lifecycle-common. - Non coroutines API from
lifecycle-viewmodel-ktxhave been moved to thelifecycle-viewmodelmodule. lifecycle-processnow usesandroidx.startupto initialize theProcessLifecycleOwner.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer.If you used
tools:node="remove"theContentProviderbeing used to initialize process lifecycle in the past, then you need to do the following instead.<provider android:name="androidx.startup.InitializationProvider" android:authorities=\"${applicationId}.androidx-startup" android:exported="false" tools:node=\"merge"> <!-- If you are using androidx.startup to initialize other components --> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" tools:node="remove" /> </provider>(یا)
<!-- If you want to disable androidx.startup completely. --> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="remove"> </provider>
Version 2.4.0-rc01
۲۹ سپتامبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-rc01 is released with no changes from Lifecycle 2.4.0-beta01. Version 2.4.0-rc01 contains these commits.
Version 2.4.0-beta01
۱۵ سپتامبر ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-beta01 is released. Version 2.4.0-beta01 contains these commits.
تغییرات API
-
@OnLifecycleEventwas deprecated.LifecycleEventObserverorDefaultLifecycleObservershould be used instead. ( I5a8fa ) - DefaultLifecycleObserver was moved from
androidx.lifecycle.lifecycle-common-java8toandroidx.lifecycle.lifecycle-common.androidx.lifecycle.lifecycle-common-java8doesn't provide anymore any additional functionality on top ofandroidx.lifecycle.lifecycle-common, so dependency on it can be replaced byandroidx.lifecycle.lifecycle-common. ( I021aa ) - Non coroutines API from
lifecycle-viewmodel-ktxhave been moved to thelifecycle-viewmodelmodule. ( I6d5b2 )
External Contribution
Version 2.4.0-alpha03
۴ آگوست ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha03 is released. Version 2.4.0-alpha03 contains these commits.
تغییرات API
- Source-breaking change : ViewModelProvider has been rewritten in Kotlin.
ViewModelProvider.Factory.createmethod no longer allows nullable generic. ( I9b9f6 )
تغییرات رفتاری
- The
Lifecycle.repeatOnLifecycle:blockis now always invoked serially when repeating execution. ( Ibab33 )
External Contribution
- Thanks chao2zhang for fixing the code snippets in the
repeatOnLifecycledocumentation. #205 .
Version 2.4.0-alpha02
۱۶ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha02 is released. Version 2.4.0-alpha02 contains these commits.
ویژگیهای جدید
- Added a new
RepeatOnLifecycleWrongUsagelint check tolifecycle-runtime-ktxthat detects whenrepeateOnLifecycleis incorrectly used inonStart()oronResume(). ( 706078 , b/187887400 )
تغییرات API
- The
LifecycleOwner.addRepeatingJobAPI is removed in favor ofLifecycle.repeatOnLifecyclethat respects structured concurrency and is easier to reason about. ( I4a3a8 ) - Make
ProcessLifecycleInitializerpublic so otherandroidx.startup.Initializers can use these as dependencies. ( I94c31 )
رفع اشکالات
- Fixed an issue with the
NullSafeMutableLiveDatalint check when the field has modifiers. ( #147 , b/183696616 ) - Fixed another issue with the
NullSafeMutableLiveDatalint check when using generics. ( #161 , b/184830263 )
External Contribution
- Thanks maxsav for improving the
NullSafeMutableLiveDatalint check. ( #147 , b/183696616 ) - Thanks kozaxinan for improving the
NullSafeMutableLiveDatalint check. ( #161 , b/184830263 )
Version 2.4.0-alpha01
۲۴ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.4.0-alpha01 is released. Version 2.4.0-alpha01 contains these commits.
تغییرات رفتاری
lifecycle-processnow usesandroidx.startupto initialize theProcessLifecycleOwner.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer.If you used
tools:node="remove"theContentProviderbeing used to initialize process lifecycle in the past, then you need to do the following instead.<provider android:name="androidx.startup.InitializationProvider" android:authorities=\"${applicationId}.androidx-startup" android:exported="false" tools:node=\"merge"> <!-- If you are using androidx.startup to initialize other components --> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" tools:node="remove" /> </provider>(یا)
<!-- If you want to disable androidx.startup completely. --> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="remove"> </provider>
تغییرات API
- Added a
Flow.flowWithLifecycleAPI that emits values from the upstream Flow when the lifecycle is at least in a certain state using theLifecycle.repeatOnLifecycleAPI. This is an alternative to the also newLifecycleOwner.addRepeatinJobAPI. ( I0f4cd )
رفع اشکالات
- From Lifecycle 2.3.1 : The
NonNullableMutableLiveDatalint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
Lifecycle Viewmodel Compose Version 1.0.0
Version 1.0.0-alpha07
۱۶ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07 is released. Version 1.0.0-alpha07 contains these commits.
Breaking API Changes
-
viewModel()now takes an optionalViewModelStoreOwner, making it easier to work with owners other than theLocalViewModelStoreOwner. For example, you can now useviewModel(navBackStackEntry)to retrieve a ViewModel associated with a particular navigation graph. ( I2628d , b/188693123 )
Version 1.0.0-alpha06
۲ ژوئن ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha06 is released. Version 1.0.0-alpha06 contains these commits.
Updated to be compatible with Compose version 1.0.0-beta08 .
Version 1.0.0-alpha05
۱۸ مه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits.
ویژگیهای جدید
- Updated to be compatible with Compose version
1.0.0-beta07.
رفع اشکالات
- The AndroidManifest files from ui-test-manifest and ui-tooling-data are now compatible with Android 12 ( I6f9de , b/184718994 )
Version 1.0.0-alpha04
۷ آوریل ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04 is released. Version 1.0.0-alpha04 contains these commits.
تغییرات وابستگی
- This version allows
androidx.hilt:hilt-navigation-composeandandroidx.navigation:navigation-composeto sync dependencies onandroidx.compose.compiler:compiler:1.0.0-beta04andandroidx.compose.runtime:runtime:1.0.0-beta04. For 1.0.0, it is required that the compiler and runtime match.
Version 1.0.0-alpha03
۱۰ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03 is released. Version 1.0.0-alpha03 contains these commits.
تغییرات API
-
LocalViewModelStoreOwner.currentnow returns a nullableViewModelStoreOwnerto better determine whether aViewModelStoreOwneris available in the current composition. APIs that require aViewModelStoreOwner, such asviewModel()andNavHost, still throw an exception if aViewModelStoreOwneris not set. ( Idf39a )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha02
۲۴ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02 is released. Version 1.0.0-alpha02 contains these commits.
تغییرات API
-
LocalViewModelStoreOwnernow has aprovidesfunctions that can be used withCompositionLocalProvider, replacing theasProvidableCompositionLocal()API. ( I45d24 )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha01
۱۰ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01 is released. Version 1.0.0-alpha01 contains these commits.
ویژگیهای جدید
- The
viewModel()composable andLocalViewModelStoreOwnerwere moved fromandroidx.compose.ui.viewinteropto this artifact in theandroidx.lifecycle.viewmodel.composepackage. ( I7a374 )
نسخه ۲.۳.۱
Lifecycle Version 2.3.1
۲۴ مارس ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.3.1 is released. Version 2.3.1 contains these commits.
رفع اشکالات
- The
NonNullableMutableLiveDatalint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
نسخه ۲.۳.۰
نسخه ۲.۳.۰
۱۰ فوریه ۲۰۲۱
androidx.lifecycle:lifecycle-*:2.3.0 is released. Version 2.3.0 contains these commits.
Major changes since 2.2.0
-
SavedStateHandlesupport for non-parcelable classes :SavedStateHandlenow supports lazy serialization by allowing you to callsetSavedStateProvider()for a given key, providing aSavedStateProviderthat will get a callback tosaveState()when theSavedStateHandleis asked to save its state. See Saving non-parcelable classes . - Lifecycle Behavior Enforcement :
- LifecycleRegistry now enforces
DESTROYEDas a terminal state. -
LifecycleRegistrynow verifies that its methods are called on main thread. It was always a requirement for lifecycles of activities, fragments etc. An addition of observers from non-main threads resulted in hard to catch crashes in runtime. ForLifecycleRegistryobjects that owned by your own components, you can explicitly opt out from checks by usingLifecycleRegistry.createUnsafe(...), but then you have to ensure that a proper synchronization is in place when thisLifecycleRegistryis accessed from different threads.
- LifecycleRegistry now enforces
- Lifecycle State and Event Helpers : Added static helper methods of
downFrom(State),downTo(State),upFrom(State),upTo(State)toLifecycle.Eventfor generating theEventgiven aStateand transition direction. Added thegetTargetState()method that provides theStatethat the Lifecycle will transition to directly following theEvent. -
withStateAtLeast: AddedLifecycle.withStateAtLeastAPIs that await a lifecycle state and run a non-suspending block of code synchronously at the point of state change, then resume with the result. These APIs differ from the existingwhen*methods as they do not permit running suspending code and do not employ a custom dispatcher. ( aosp/1326081 ) -
ViewTreeAPIs : A newViewTreeLifecycleOwner.get(View)andViewTreeViewModelStoreOwner.get(View)API allows you to retrieve the containingLifecycleOwnerandViewModelStoreOwner, respectively, given aViewinstance. You must upgrade to Activity1.2.0and Fragment1.3.0, and AppCompat 1.3.0-alpha01 or higher to populate this correctly. ThefindViewTreeLifecycleOwnerandfindViewTreeViewModelStoreOwnerKotlin extensions are available inlifecycle-runtime-ktxandlifecycle-viewmodel-ktx, respectively. -
LiveData.observe()Kotlin extension deprecation : TheLiveData.observe()Kotlin extension necessary to use lambda syntax is now deprecated as it is not necessary when using Kotlin 1.4.
Version 2.3.0-rc01
۱۶ دسامبر ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-rc01 is released. Version 2.3.0-rc01 contains these commits.
رفع اشکالات
- The
keys()method ofSavedStateHandleis now consistent before and after the state is saved - it now includes keys previously used withsetSavedStateProvider()in addition to the keys used withset()andgetLiveData(). ( aosp/1517919 , b/174713653 )
External Contribution
- The APIs to suspend Lifecycle-aware coroutines now better handle calls to
yield(). Thanks Nicklas Ansman Giertz! ( aosp/1430830 , b/168777346 )
Version 2.3.0-beta01
۱ اکتبر ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-beta01 is released. Version 2.3.0-beta01 contains these commits.
تغییرات API
- The
LiveData.observe()Kotlin extension necessary to use lambda syntax is now deprecated as it is not necessary when using Kotlin 1.4. ( I40d3f )
رفع اشکالات
- Upgrade androidx to use Kotlin 1.4 ( Id6471 , b/165307851 , b/165300826 )
Documentation Changes
- The
liveDatabuilder andasLiveData()docs have been updated to include details about changing the given timeout values. ( aosp/1122324 )
Version 2.3.0-alpha07
۱۹ آگوست ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha07 is released. Version 2.3.0-alpha07 contains these commits.
رفع اشکالات
- Fixed a crash issue in the
NullSafeMutableLiveDataLint check. ( aosp/1395367 )
Version 2.3.0-alpha06
۲۲ ژوئیه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha06 is released. Version 2.3.0-alpha06 contains these commits.
ویژگیهای جدید
- Added static helper methods of
downFrom(State),downTo(State),upFrom(State),upTo(State)toLifecycle.Eventfor generating theEventgiven aStateand transition direction. Added thegetTargetState()method that provides theStatethat the Lifecycle will transition to directly following theEvent. ( I00887 ) - Added
Lifecycle.withStateAtLeastAPIs that await a lifecycle state and run a non-suspending block of code synchronously at the point of state change, then resume with the result. These APIs differ from the existingwhen*methods as they do not permit running suspending code and do not employ a custom dispatcher. ( aosp/1326081 )
تغییرات رفتاری
- LifecycleRegistry now enforces
DESTROYEDas a terminal state. ( I00887 ) -
LifecycleRegistrynow verifies that its methods are called on main thread. It was always a requirement for lifecycles of activities, fragments etc. An addition of observers from non-main threads resulted in hard to catch crashes in runtime. ForLifecycleRegistryobjects that owned by your own components, you can explicitly opt out from checks by usingLifecycleRegistry.createUnsafe(...), but then you have to ensure that a proper synchronization is in place when thisLifecycleRegistryis accessed from different threads ( Ie7280 , b/137392809 )
رفع اشکالات
- Fixed a crash in
NullSafeMutableLiveData. ( b/159987480 ) - Fixed an
ObsoleteLintCustomCheckfor Lint checks bundled withlifecycle-livedata-core-ktx(and specificallyNullSafeMutableLiveData). ( b/158699265 )
Version 2.3.0-alpha05
۲۴ ژوئن ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha05 is released. Version 2.3.0-alpha05 contains these commits.
رفع اشکالات
-
LiveDatanow better handles reentrant cases, avoiding duplicate calls toonActive()oronInactive(). ( b/157840298 ) - Fixed an issue where Lint checks would not run when using Android Studio 4.1 Canary 6 or higher. ( aosp/1331903 )
Version 2.3.0-alpha04
۱۰ ژوئن ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha04 is released. Version 2.3.0-alpha04 contains these commits.
رفع اشکالات
- Fixed a crash in the
NonNullableMutableLiveDataLint check. ( b/157294666 ) - The
NonNullableMutableLiveDataLint check now covers significantly more cases where anullvalue was set on aMutableLiveDatawith a non-null type parameter. ( b/156002218 )
Version 2.3.0-alpha03
۲۰ مه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha03 are released. Version 2.3.0-alpha03 contains these commits.
ویژگیهای جدید
-
SavedStateHandlenow supports lazy serialization by allowing you to callsetSavedStateProvider()for a given key, providing aSavedStateProviderthat will get a callback tosaveState()when theSavedStateHandleis asked to save its state. ( b/155106862 ) - A new
ViewTreeViewModelStoreOwner.get(View)API allows you to retrieve the containingViewModelStoreOwnergiven aViewinstance. You must upgrade to Activity1.2.0-alpha05, Fragment1.3.0-alpha05, and AppCompat1.3.0-alpha01to populate this correctly. AfindViewModelStoreOwner()Kotlin extension has been added tolifecycle-viewmodel-ktx. ( aosp/1295522 )
رفع اشکالات
- Fixed an issue that caused the
MutableLiveDataLint checks released in Lifecycle2.3.0-alpha01from being published alongside thelifecycle-livedata-core-ktxartifact. ( b/155323109 )
Version 2.3.0-alpha02
۲۹ آوریل ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha02 is released. Version 2.3.0-alpha02 contains these commits.
تغییرات API
-
SavedStateViewModelFactorynow allows you to pass a nullApplicationto its constructor to better support cases where one is not readily available and support forAndroidViewModelis not needed. ( aosp/1285740 )
رفع اشکالات
- Improved cold start performance by avoiding class verification failure on API 28 and lower devices. ( aosp/1282118 )
Version 2.3.0-alpha01
۴ مارس ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.3.0-alpha01 is released. Version 2.3.0-alpha01 contains these commits.
ویژگیهای جدید
- A new
ViewTreeLifecycleOwner.get(View)API allows you to retrieve the containingLifecycleOwnergiven aViewinstance. You must upgrade to Activity1.2.0-alpha01and Fragment1.3.0-alpha01to populate this correctly. AfindViewTreeLifecycleOwnerKotlin extension is available inlifecycle-runtime-ktx. ( aosp/1182361 , aosp/1182956 ) - Added a new Lint check that warns you when setting a
nullvalue on aMutableLiveDatathat has been defined in Kotlin as non-null. This is available when using thelivedata-core-ktxorlivedata-ktxartifacts. ( aosp/1154723 , aosp/1159092 ) - A new
lifecycle-runtime-testingartifact is available that provides aTestLifecycleOwnerthat implementsLifecycleOwnerand provides a thread safe mutableLifecycle. ( aosp/1242438 )
رفع اشکالات
- The
lifecycle-runtimeartifact now has a unique package name. ( aosp/1187196 )
نسخه ۲.۲.۰
ViewModel-Savedstate Version 2.2.0
۵ فوریه ۲۰۲۰
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0 is released. Version 2.2.0 contains these commits .
Lifecycle ViewModel SavedState now shares the same version as other Lifecycle artifacts. The behavior of 2.2.0 is identical to the behavior of 1.0.0 .
نسخه ۲.۲.۰
۲۲ ژانویه ۲۰۲۰
androidx.lifecycle:lifecycle-*:2.2.0 is released. Version 2.2.0 contains these commits .
Important changes since 2.1.0
- Lifecycle Coroutine Integration : The new
lifecycle-runtime-ktxartifact adds integration between Lifecycle and Kotlin coroutines. Thelifecycle-livedata-ktxhas also been expanded to take advantage of coroutines. See Use Kotlin coroutines with Architecture Components for more details. -
ViewModelProviders.of()deprecation :ViewModelProviders.of()has been deprecated. You can pass aFragmentorFragmentActivityto the newViewModelProvider(ViewModelStoreOwner)constructor to achieve the same functionality when using Fragment1.2.0. -
lifecycle-extensionsArtifact Deprecation : With the above deprecation ofViewModelProviders.of(), this release marks the deprecation of the last API inlifecycle-extensionsand this artifact should now be considered deprecated in its entirety. We strongly recommend depending on the specific Lifecycle artifacts you need (such aslifecycle-serviceif you're usingLifecycleServiceandlifecycle-processif you're usingProcessLifecycleOwner) rather thanlifecycle-extensionsas there will not be a future2.3.0release oflifecycle-extensions. - Gradle Incremental Annotation Processor : Lifecycle's annotation processor is incremental by default. If your app is written in the Java 8 programming language you can use
DefautLifecycleObserverinstead; and if it's written in the Java 7 programming language you can useLifecycleEventObserver.
Version 2.2.0-rc03
۴ دسامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc03 is released. Version 2.2.0-rc03 contains these commits .
رفع اشکالات
- Fixed a failure occurring when a mocked
ViewModelwas stored inViewModelStoreand queried later with default factory. - Fix a usage of
Dispatchers.Main.immediateinlaunchWhenCreatedand similar methods to be called synchronously during corresponding lifecycle event. ( aosp/1156203 )
مشارکتهای خارجی
- Thanks to Anders Järleberg for contributing the fix! ( aosp/1156203 )
- Thanks to Vsevolod Tolstopyatov from Jetbrains for reviewing an implementation of inlined execution.
Dependency changes
- Lifecycle Extensions now depends on Fragment
1.2.0-rc03.
Version 2.2.0-rc02
۷ نوامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc02 is released. Version 2.2.0-rc02 contains these commits .
رفع اشکالات
- Fixed a bug in the proguard setup of the library that affected devices running API 28+ if the target API is below 29. ( b/142778206 )
Version 2.2.0-rc01
۲۳ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-rc01 is released. Version 2.2.0-rc01 contains these commits .
رفع اشکالات
- Fixed an issue where
launchWhenCreatedand related methods would run one frame later than the associated lifecycle method due to its use ofDispatchers.Maininstead ofDispatchers.Main.immediate. ( aosp/1145596 )
مشارکتهای خارجی
- Thanks to Nicklas Ansman for contributing the fix! ( aosp/1145596 )
Version 2.2.0-beta01
۹ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-beta01 is released. Version 2.2.0-beta01 contains these commits .
رفع اشکالات
- Fixed a regression introduced in Lifecycle 2.2.0-alpha05 in the ordering of
ProcessLifecycleOwnerand the activity'sLifecycleOwnermoving to started and resumed on Android 10 devices. ( aosp/1128132 ) - Fixed a regression introduced in Lifecycle
2.2.0-alpha05which would cause aNullPointerExceptionwhen using version2.0.0or2.1.0oflifecycle-process. ( b/141536990 )
Version 2.2.0-alpha05
۱۸ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha05 is released. Version 2.2.0-alpha05 contains these commits .
رفع اشکالات
- Fixed a race condition in coroutine livedata builder. b/140249349
Version 2.2.0-alpha04
۵ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha04 is released. The commits included in this version can be found here .
ویژگیهای جدید
-
lifecycleScope,whenCreated,whenStarted,whenResumed,viewModelScope, and the underlying implementation ofliveDatanow useDispatchers.Main.immediateinstead ofDispatchers.Main. ( b/139740492 )
مشارکتهای خارجی
- Thanks to Nicklas Ansman for contributing the move to
Dispatchers.Main.immediate! ( aosp/1106073 )
Version 2.2.0-alpha03
۷ آگوست ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.2.0-alpha03 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Implementations of
ViewModelStoreOwnercan now optionally implementHasDefaultViewModelProviderFactoryto provide a defaultViewModelProvider.Factory. This has been done for Activity1.1.0-alpha02, Fragment1.2.0-alpha02, and Navigation2.2.0-alpha01. ( aosp/1092370 , b/135716331 )
API changes
-
ViewModelProviders.of()has been deprecated. You can pass aFragmentorFragmentActivityto the newViewModelProvider(ViewModelStoreOwner)constructor to achieve the same functionality. ( aosp/1009889 )
Version 2.2.0-alpha02
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:*:2.2.0-alpha02 is released. The commits included in this version can be found here .
API changes
- Replaced
LiveDataScope.initialValuewithLiveDataScope.latestValuewhich will track the current emitted value of theliveDatablock. - Added a new overload to the
liveDatabuilder that receivestimeoutparameter as typeDuration
Version 2.2.0-alpha01
۷ مه ۲۰۱۹
androidx.lifecycle:*:2.2.0-alpha01 is released. The commits included in this version can be found here .
ویژگیهای جدید
- This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here .
ViewModel-SavedState Version 1.0.0
نسخه ۱.۰.۰
۲۲ ژانویه ۲۰۲۰
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0 is released. Version 1.0.0 contains these commits .
Important features in 1.0.0
- New SavedStateHandle class was added. It enables your
ViewModelclasses to access and to contribute to the saved state. This object can be received in constructor ofViewModelclass and factories provided by default by Fragments and AppCompatActivity will injectSavedStateHandleautomatically. - AbstractSavedStateViewModelFactory was added. It allows you to create custom factories for your
ViewModeland provide them access toSavedStateHandle.
ViewModel-Savedstate Version 1.0.0-rc03
۴ دسامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc03 is released. Version 1.0.0-rc03 contains these commits .
Dependency changes
- Lifecycle ViewModel SavedState now depends on Lifecycle
2.2.0-rc03.
Viewmodel-Savedstate Version 1.0.0-rc02
۷ نوامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc02 is released. Version 1.0.0-rc02 contains these commits .
Dependency changes
- Now depends on lifecycle
2.2.0-rc02.
ViewModel-SavedState Version 1.0.0-rc01
۲۳ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc01 is released with no changes from 1.0.0-beta01 . Version 1.0.0-rc01 contains these commits .
ViewModel-Savedstate Version 1.0.0-beta01
۹ اکتبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01 is released. Version 1.0.0-beta01 contains these commits .
رفع اشکالات
- Fixed an issue where accessing a SavedState ViewModel for the first time in
Activity.onActivityResult()would result in anIllegalStateException. ( b/139093676 ) - Fixed an
IllegalStateExceptionwhen usingAbstractSavedStateViewModelFactory. ( b/141225984 )
ViewModel-SavedState Version 1.0.0-alpha05
۱۸ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits .
API changes
-
SavedStateViewModelFactoryno longer extendsAbstractSavedStateViewModelFactoryandSavedStateHandleis created only for ViewModels that requested have it ( aosp/1113593 )
ViewModel-SavedState Version 1.0.0-alpha03
۷ آگوست ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03 is released. The commits included in this version can be found here .
تغییرات اساسی
-
lifecycle-viewmodel-savedstateno longer depends onfragmentand the relatedSavedStateViewModelFactory(Fragment)andSavedStateViewModelFactory(FragmentActivity)constructors have been removed. Instead,SavedStateViewModelFactoryis now the default factory for Activity1.1.0-alpha02, Fragment1.2.0-alpha02, and Navigation2.2.0-alpha01. ( b/135716331 )
ViewModel-SavedState Version 1.0.0-alpha02
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha02 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Added
SavedStateHandle.getLiveData()overload which accepts a default value.
تغییرات API
-
SavedStateVMFactoryis renamed toSavedStateViewModelFactory. -
AbstractSavedStateVMFactoryis renamed toAbstractSavedStateViewModelFactory.
ViewModel-Savedstate Version 1.0.0-alpha01
۱۳ مارس ۲۰۱۹
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01 is released. The full commit log for this initial release can be found here .
ویژگیهای جدید
- Now
ViewModelscan contribute to savedstate. To do that you use newly introduced viewmodel's factorySavedStateVMFactoryand your ViewModel should have a constructor that receivesSavedStateHandleobject as a parameter.
نسخه ۲.۱.۰
Important changes since 2.0.0
- Added
LifecycleEventObserverfor the cases when a stream of lifecycle events is needed. It is a public API instead of a hiddenGenericLifecycleObserverclass. - Added ktx extensions for
LiveData.observemethods andTransformations.*methods. - Added
Transformations.distinctUntilChanged, which creates a new LiveData object that does not emit a value until the sourceLiveDatavalue has been changed. - Added coroutine support in ViewModels by adding the extension property
ViewModel.viewModelScope.
نسخه ۲.۱.۰
۵ سپتامبر ۲۰۱۹
androidx.lifecycle:lifecycle-*:2.1.0 is released. The commits included in this version can be found here .
Version 2.1.0-rc01
۲ ژوئیه ۲۰۱۹
androidx.lifecycle:*:2.1.0-rc01 is released with no changes from androidx.lifecycle:*:2.1.0-beta01 . The commits included in this version can be found here .
Version 2.1.0-beta01
۷ مه ۲۰۱۹
androidx.lifecycle:*:2.1.0-beta01 is released. The commits included in this version can be found here .
ویژگیهای جدید
- Lifecycles are graduated to beta: api introduced in previous alphas such as
liveDataextension functions for transformations and observations,ViewModelinitialisation with property delegation and others are stabilised and not going to change.
Version 2.1.0-alpha04
۳ آوریل ۲۰۱۹
androidx.lifecycle:*:2.1.0-alpha04 is released. The commits included in this version can be found here .
API changes
- Breaking change: the underlying API behind
by viewModels()andby activityViewModels()has been changed to support aViewModelStoredirectly, rather than only aViewModelStoreOwner. ( aosp/932932 )
Version 2.1.0-alpha03
۱۳ مارس ۲۰۱۹
androidx.lifecycle:*:2.1.0-alpha03 is released. The full list of commits included in this version can be found here .
API changes
-
ViewModelProvider.KeyedFactorywas removed. Second interface in addition toViewModelProvider.Factorydidn't compose well with new features as property delegation in Kotlinby viewmodels {}. ( aosp/914133 )
Version 2.1.0-alpha02
۳۰ ژانویه ۲۰۱۹
androidx.lifecycle 2.1.0-alpha02 is released.
API changes
-
LifecycleRegistrynow contains asetCurrentState()method that replaces the now deprecatedsetState()method. ( aosp/880715 )
رفع اشکالات
- Fixed an issue where mock
ViewModelinstances would crash when the containingViewModelStorewas cleared. b/122273087
Version 2.1.0-alpha01
۱۷ دسامبر ۲۰۱۸
androidx.lifecycle 2.1.0-alpha01 is released.
ویژگیهای جدید
- Added
LifecycleEventObserverfor the cases when a stream of lifecycle events is needed. It is a public api instead of a hiddenGenericLifecycleObserverclass. - Added ktx extensions for
LiveData.observemethods andTransformations.*methods. - Method
Transformations.distinctUntilChangedwas added. It creates a newLiveDataobject that does not emit a value until the source LiveData value has been changed. - Coroutine support in ViewModels: extension property
ViewModel.viewModelScopewas added. - Added
ViewModelProvider.KeyedFactory, a factory for ViewModels that receiveskeyandClassincreatemethod.
نسخه ۲.۰.۰
نسخه ۲.۰.۰
۲۱ سپتامبر ۲۰۱۸
Lifecycle 2.0.0 is released with one bugfix from 2.0.0-rc01 in ViewModel.
رفع اشکالات
- Fixed a ViewModel proguard rule that incorrectly removed constructors b/112230489
Version 2.0.0-beta01
July 2, 2018
رفع اشکالات
- Fixed LifecycleObserver proguard rule to keep only implementations, not subinterfaces b/71389427
- Fixed ViewModel proguard rules to allow obfuscation and shrinking
Pre-AndroidX Versions
For the pre-AndroidX versions of Lifecycle that follow, include these dependencies:
dependencies {
def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// alternatively - just ViewModel
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version" // For Kotlin use viewmodel-ktx
// alternatively - just LiveData
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
// alternatively - Lifecycles only (no ViewModel or LiveData).
// Support library depends on this lightweight import
implementation "android.arch.lifecycle:runtime:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" // For Kotlin use kapt instead of annotationProcessor
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
// optional - ReactiveStreams support for LiveData
implementation "android.arch.lifecycle:reactivestreams:$lifecycle_version"
// optional - Test helpers for LiveData
testImplementation "android.arch.core:core-testing:$lifecycle_version"
}
نسخه ۱.۱.۱
۲۱ مارس ۲۰۱۸
Only one small change: android.arch.core.util.Function is moved from arch:runtime to arch:common . This allows it to be used without the runtime dependency, eg in paging:common below.
lifecycle:common is a dependency of lifecycle:runtime , so this change doesn't affect lifecycle:runtime directly, only modules that depend directly on lifecycle:common , as Paging does.
نسخه ۱.۱.۰
۲۲ ژانویه ۲۰۱۸
Packaging Changes
New, much smaller dependencies are now available:
-
android.arch.lifecycle:livedata:1.1.0 -
android.arch.lifecycle:viewmodel:1.1.0
تغییرات API
- The deprecated
LifecycleActivityandLifecycleFragmenthave now been removed - please useFragmentActivity,AppCompatActivityor supportFragment. -
@NonNullannotations have been added toViewModelProvidersandViewModelStores -
ViewModelProvidersconstructor has been deprecated - please use its static methods directly -
ViewModelProviders.DefaultFactoryhas been deprecated - please useViewModelProvider.AndroidViewModelFactory - The static
ViewModelProvider.AndroidViewModelFactory.getInstance(Application)method has been added to retrieve a staticFactorysuitable for creatingViewModelandAndroidViewModelinstances.