چرخه زندگی
این جدول تمام مصنوعات موجود در گروه androidx.lifecycle
را فهرست می کند.
مصنوع | انتشار پایدار | کاندید را آزاد کنید | نسخه بتا | انتشار آلفا |
---|---|---|---|---|
چرخه زندگی-* | 2.8.7 | - | - | 2.9.0-آلفا10 |
lifecycle-viewmodel-compose | 2.8.7 | - | - | 2.9.0-آلفا10 |
اعلام وابستگی ها
برای افزودن وابستگی به Lifecycle، باید مخزن Google Maven را به پروژه خود اضافه کنید. برای اطلاعات بیشتر، مخزن Maven Google را بخوانید.
وابستگیهای مصنوعات مورد نیاز خود را در فایل build.gradle
برای برنامه یا ماژول خود اضافه کنید:
کاتلین
شیار
dependencies { def lifecycle_version = "2.8.7" 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" // 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.8.7" 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") // 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.8.7" 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.8.7" 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 کمک می کند. اگر مسائل جدیدی کشف کردید یا ایده هایی برای بهبود این کتابخانه دارید، به ما اطلاع دهید. لطفاً قبل از ایجاد کتابخانه جدید، به مسائل موجود در این کتابخانه نگاهی بیندازید. با کلیک کردن روی دکمه ستاره می توانید رای خود را به یک موضوع موجود اضافه کنید.
برای اطلاعات بیشتر به مستندات ردیاب مشکل مراجعه کنید.
نسخه 2.9
نسخه 2.9.0-alpha10
12 فوریه 2025
androidx.lifecycle:lifecycle-*:2.9.0-alpha10
منتشر شد. نسخه 2.9.0-alpha10 حاوی این commit ها است.
تغییرات API
-
MutableStateSerializer
بهsavedstate-compose
ازlifecycle-viewmodel-compose
منتقل کنید. ( I4f690 , b/378895074 )
مشارکت خارجی
- یک مشکل جدید Lint را برای فراخوانی
Lifecycle::currentState
در ترکیب اضافه میکند، به جای آن پیشنهاد میکند که ازcurrentStateAsalue().value
کنید تا اطمینان حاصل شود که تغییرات در حالت چرخه زندگی به درستی باعث ترکیب مجدد میشود. متشکرم استیون شوئن! ( Iad484 )
نسخه 2.9.0-alpha09
29 ژانویه 2025
androidx.lifecycle:lifecycle-*:2.9.0-alpha09
منتشر شد. نسخه 2.9.0-alpha09 حاوی این commit ها است.
ویژگی های جدید
-
MutableStateSerializer
برای سریال سازیandroidx.compose.runtime.MutableState
اضافه کنید. ( Idfc48 , b/378895074 )
تغییرات API
- توابع ارسال شده
SavedStateHandle.saved()
با پارامترهای پیش فرض جایگزین کنید ( Icd1c1 ) -
AbstractSavedStateViewModelFactory
منسوخ شده است زیرا یکSavedStateHandle
برای هرViewModel
ایجاد می کند و باعث سربار غیر ضروری می شود. برای ایجاد کارآمدترViewModel
به جای آن ازViewModelProvider.Factory
باCreationExtras.createSavedStateHandle
استفاده کنید. ( Ia920b , b/388590327 )
نسخه 2.9.0-alpha08
11 دسامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha08
منتشر شد. نسخه 2.9.0-alpha08 حاوی این تعهدات است.
ویژگی های جدید
-
ViewModelScenario.recreate
را اضافه کنید تا یک System Process Death شبیه سازی شود کهViewModel
تحت آزمایش و تمام اجزای مرتبط را بازسازی می کند. ( ID6a69 , b/381063087 ) - نمونههای
LifecycleOwner
وViewModelStoreOwner
که از طریق APIهایfindViewTree
مربوطه خود بازیابی میشوند، اکنون میتوانند از طریق والدین مجزای یک view، مانندViewOverlay
حل شوند. برای اطلاعات بیشتر در مورد والدین با نمای جدا، به یادداشتهای انتشار هسته یا مستندات درViewTree.setViewTreeDisjointParent
مراجعه کنید. ( I800f4 )
تغییرات API
- نامگذاری و سازماندهی بستهها را با
SavedStateRegistryOwnerDelegate
سازگارتر کنید ( I8c135 , b/376026744 )
رفع اشکال
- این کتابخانه اکنون از حاشیهنویسیهای پوچ JSpecify استفاده میکند که نوع استفاده هستند. توسعه دهندگان Kotlin باید از آرگومان های کامپایلر زیر برای اعمال استفاده صحیح استفاده کنند:
-Xjspecify-annotations=strict, -Xtype-enhancement-improvements-strict-mode
( Ie4340 , b/326456246 ) - Document
ViewModel.onCleared
توالی پاکسازی پاک شده. ( I586c7 , b/363984116 )
نسخه 2.9.0-alpha07
13 نوامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha07
منتشر شد. نسخه 2.9.0-alpha07 حاوی این commit ها است.
سازگاری چند پلتفرمی Kotlin
- Lifecycle
ViewModel SavedState
اکنون با KMP سازگار است. این به شما امکان می دهد ازSavedStateHandle
در کدهای رایج استفاده کنید. ( Ib6394 , b/334076622 )
پشتیبانی از سریال سازی KotlinX
با پشتیبانی از KotlinX Serialization که در SavedState
1.3.0-alpha05
اضافه شده است،saved
معرفی کردهایم، یک نماینده ویژگی تنبل، تا ذخیره کلاسهای@Serializable
در یکSavedStateHandle
را آسان کنیم و آن کلاسها به طور خودکار در طول فرآیند مرگ و بازیابی بازیابی شوند. لطفاً توجه داشته باشید که نمایندهsaved
تنبل است و تا زمانی که به آن دسترسی پیدا نشود،init
lambda را صدا نمی کند یا چیزی را در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
- برای بازگشت یک
MutableStateFlow
getMutableStateFlow
بهSavedStateHandle
اضافه کنید. این تابع جدید انحصاری کلید است و باgetLiveData
قابل استفاده نیست. اگر سعی کنید از هر دو برای دسترسی به یک حالت استفاده کنید، یک استثنا ایجاد می شود. ( I04a4f , b/375408415 )
نسخه 2.9.0-alpha06
30 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha06
منتشر شد. نسخه 2.9.0-alpha06 حاوی این commit ها است.
تغییرات رفتار
- حالت
Lifecycle.DESTROYED
پایانه است و هر تلاشی برای انتقال یکLifecycle
از آن به هر حالت دیگری اکنون منجر به یکIllegalStateException
می شود. ( I116c4 , b/370577987 ) -
SavedStateHandle
دیگر شاملSavedStateProvider.saveState()
نمی شود که در آنBundle
بازگشتی خالی باشد. ( I910b5 , b/370577987 )
رفع اشکال
-
Lifecycle.eventFlow
اکنون باDESTROYED
Lifecycle
به درستی کامل می شود ( I293b2 , b/374043130 )
نسخه 2.9.0-alpha05
16 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha05
بدون هیچ تغییر قابل توجهی منتشر شد. نسخه 2.9.0-alpha05 حاوی این commit ها است.
نسخه 2.9.0-alpha04
2 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha04
منتشر شد. نسخه 2.9.0-alpha04 حاوی این commit ها است.
چند پلتفرم کاتلین
- ماژول
lifecycle-viewmodel-savedstate
اکنون برای سازگاری با KMP برای آمادهسازی APIهایی مانندSavedStateHandle
که در مجموعه منبع مشترک در نسخههای آینده در دسترس قرار میگیرند، پیکربندی شده است. ( I503ed , I48764 , b/334076622 )
نسخه 2.9.0-alpha03
18 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha03
منتشر شد. نسخه 2.9.0-alpha03 حاوی این commit ها است.
رفع اشکال
- از Lifecycle
2.8.6
: خطایNullSafeMutableLiveData
Lint پشتیبانی از پخش هوشمند را بهبود بخشیده است و از مثبت کاذب جلوگیری می کند. ( 85fed6 , b/181042665 )
به روز رسانی های وابستگی
- از Lifecycle
2.8.6
: Lifecycle Runtime Compose اکنون به Compose Runtime1.7.1
بستگی دارد - Lifecycle Runtime اکنون به ProfileInstaller
1.4.0
بستگی دارد
نسخه 2.9.0-alpha02
4 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha02
منتشر شد. نسخه 2.9.0-alpha02 حاوی این commit ها است.
رفع اشکال
- از Lifecycle
2.8.5
: قوانینandroidx.lifecycle.ReportFragment
ProGuard را به روز کنید تا مبهم سازی امکان پذیر باشد. ( ff898e1 )
مشارکت خارجی
-
androidx.compose.ui.platform.LocalLifecycleOwner
به مجموعه منبع مشترک (KMP) منتقل کنید. با تشکر از ایوان ماتکوف از JetBrains برای کمک. ( 8cd5d03 ) - از Lifecycle
2.8.5
: نماینده پسوند SavedStateHandle.saveable اکنون از مقادیر nullable پشتیبانی می کند. با تشکر از رومن کالوکیویچ برای مشارکت. ( 0d78ea6 )
نسخه 2.9.0-alpha01
7 آگوست 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha01
منتشر شد. نسخه 2.9.0-alpha01 حاوی این commit ها است.
چند پلتفرم کاتلین
-
lifecycle-testing
اکنون با KMP سازگار است. ( Iea41e ) - افزودن پشتیبانی برای هدف چند پلتفرمی
linuxArm64
kotlin ( I139d3 , b/338268719 )
ویژگی های جدید
- یک مصنوع KMP جدید
androidx.lifecycle:lifecycle-viewmodel-testing
موجود است که یک کلاسViewModelScenario
برای آزمایش ViewModels به صورت مجزا، با پشتیبانی ازonCleared
(همه پلتفرمها) وSavedStateHandle
(فقط اندروید) ارائه میکند. ( 337f68d , c9b3409 , 9799a95c , b/264602919 ) - ایجاد
ViewModel
باViewModelProvider
در حال حاضر موضوعی امن است. حاشیه نویسی@MainThread
حذف شده است. ( Ifd978 , b/237006831 )
تغییرات API
- تابع کارخانه
CreationExtras.Key()
را اضافه کنید تا ایجاد اشیاءCreationExtras.Key
ناشناس را ساده کنید. ( I970ee ) -
CreationExtras
اکنون شامل اضافه بارهای اپراتور شبیه به نقشه برای فعال کردن دستکاری اصطلاحی محتوا در Kotlin است. این اجازه می دهد تا ازin
،+=
، و+
باCreationExtras
استفاده کنید. ( Ib4353 ) - اکنون
CreationExtras
متدهایequals
،hashCode
وtoString
را پیاده سازی می کند. ( Ib4353 ) -
NewInstanceFactory
اکنون در JVM Desktop و اهداف Android در دسترس است. ( d3d0892 ) - ویژگی افزونه درون خطی برای نمایش امن برنامه زیربنایی در زبان Kotlin نسخه 2.0 ( I39df2 )
رفع اشکال
- طرح دستی دسترسی به APIهای پلتفرم جدید حذف شد زیرا این به طور خودکار از طریق مدلسازی API هنگام استفاده از R8 با AGP 7.3 یا جدیدتر (مثلا R8 نسخه 3.3) و برای همه ساختها هنگام استفاده از AGP 8.1 یا بالاتر (به عنوان مثال D8 نسخه 8.1) اتفاق میافتد. به مشتریانی که از AGP استفاده نمیکنند، توصیه میشود به نسخه 8.1 یا بالاتر D8 بهروزرسانی کنند. برای جزئیات بیشتر به این مقاله مراجعه کنید. ( If6b4c , b/345472586 )
نسخه 2.8
نسخه 2.8.7
30 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.8.7
منتشر شد. نسخه 2.8.7 شامل این commit ها است.
تغییرات API
-
androidx.compose.ui.platform.LocalLifecycleOwner
اکنون در مجموعه منبع مشترک (KMP) در دسترس است. ( 6a3f5b3 ) -
lifecycle-runtime-compose
: مصنوعاتdesktop
حذف شدند و مصنوعات-jvmStubs
و-linuxx64Stubs
اضافه شدند. هیچ یک از این اهداف قرار نیست مورد استفاده قرار گیرند، آنها مکان هایی هستند که به تلاش های Jetbrains Compose کمک می کنند. ( 6a3f5b3 )
نسخه 2.8.6
18 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.8.6
منتشر شد. نسخه 2.8.6 حاوی این commit ها است.
رفع اشکال
- خطای
NullSafeMutableLiveData
Lint پشتیبانی از پخش هوشمند را بهبود بخشیده است و از مثبت کاذب جلوگیری می کند. ( 85fed6 , b/181042665 )
به روز رسانی های وابستگی
- Lifecycle Runtime Compose اکنون به Compose Runtime
1.7.1
بستگی دارد
نسخه 2.8.5
4 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.8.5
منتشر شد. نسخه 2.8.5 حاوی این commit ها است.
رفع اشکال
- قوانین
androidx.lifecycle.ReportFragment
ProGuard را به روز کنید تا مبهم سازی امکان پذیر باشد. ( ff898e1 )
مشارکت خارجی
- نماینده پسوند
SavedStateHandle.saveable
اکنون از مقادیر nullable پشتیبانی می کند. با تشکر از رومن کالوکیویچ برای مشارکت. ( 0d78ea6 )
نسخه 2.8.4
24 جولای 2024
androidx.lifecycle:lifecycle-*:2.8.4
منتشر شد. نسخه 2.8.4 حاوی این commit ها است.
رفع اشکال
- اکنون
LiveData.asFlow()
به درستی مواردی را که در آن Flow برگشتی بلافاصله پس از دریافت مقداری که قبلاً درLiveData
تنظیم شده است تکمیل می شود (به عنوان مثال، هنگام استفاده ازtake(1)
). ( I9c566 ) -
Lifecycle*Effect
اکنون بیتوان است (به عنوان مثال، اگرonStopOrDispose
به دلیل توقف چرخه حیات فراخوانی شده باشد، برای بار دوم پس از دور ریختن فراخوانی نمیشود مگر اینکه چرخه حیات دوباره بهSTARTED
برگردد). ( I5f607 , b/352364595 )
نسخه 2.8.3
1 ژوئیه 2024
androidx.lifecycle:lifecycle-*:2.8.3
منتشر شد. نسخه 2.8.3 شامل این commit ها است.
رفع اشکال
- مشکل سازگاری رو به عقب Lifecycle 2.8 با Compose 1.6.0 و پایین تر هنگام استفاده از کوچک کردن کد برطرف شد. ( aosp/3133056 , b/346808608 )
نسخه 2.8.2
12 ژوئن 2024
androidx.lifecycle:lifecycle-*:2.8.2
منتشر شد. نسخه 2.8.2 شامل این commit ها است.
رفع اشکال
- رفع مشکل
CompositionLocal LocalLifecycleOwner not present
- اکنون میتوانید از Lifecycle 2.8.2 با هر نسخه از Compose بدون هیچ راهحلی استفاده کنید. ( aosp/3105647 , b/336842920 ) - هنگام مخلوط کردن نسخههای قبلی وابستگیهای
compileOnly
Lifecycle با نسخههای 2.8+،ViewModelProvider
دیگر خراب نمیشود و مشکلات کتابخانههایی مانند LeakCanary را برطرف میکند. ( I80383 , b/341792251 )
نسخه 2.8.1
29 مه 2024
androidx.lifecycle:lifecycle-*:2.8.1
منتشر شد. نسخه 2.8.1 حاوی این commit ها است.
رفع اشکال
-
lifecycle-viewmodel-compose
اکنون فقط یک وابستگی مشترک بهcompose-runtime
دارد و وابستگی رایج آن بهcompose-ui
حذف میشود. مصنوع اندرویدیcompose-ui
خود را برای سازگاری حفظ می کند. ( aosp/3079334 , b/339562627 ) - ادغام
saveable
ViewModel
با استفاده از نمایندگان ویژگی، اکنون از نام کلاس به عنوان بخشی از کلید تولید شده خودکار استفاده می کند، و اگر چندین کلاس ازSavedStateHandle
یکسان استفاده کنند، از تداخل جلوگیری می کند. ( aosp/3063463 )
نسخه 2.8.0
14 مه 2024
androidx.lifecycle:lifecycle-*:2.8.0
منتشر شد. نسخه 2.8.0 شامل این commit ها است.
تغییرات مهم از 2.7.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
اکنون یک پارامتر سازنده قابل لغو است که به شما امکان می دهد توزیع کننده و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
در Kotlin بازنویسی شده است و اکنون ازAutoClosable
به جایCloseable
استفاده می کند. اکنون از افزودن اشیایAutoCloseable
باkey
پشتیبانی می کند که امکان بازیابی آنها را از طریقgetCloseable()
فراهم می کند.فراخوانی
LifecycleStartEffect
وLifecycleResumeEffect
بدون کلید اکنون یک خطا است و از همان قراردادDisposableEffect
API پیروی می کند که این APIها منعکس می کنند.LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)
به نفعLiveData.toPublisher(lifecycleOwner)
منسوخ شد.پسوندهای
lifecycle-livedata-core-ktx
kotlin اکنون به ماژولlifecycle-livedata-core
منتقل شدهاند.NullSafeMutableLiveData
برای جلوگیری از بسیاری از موارد مثبت کاذب مجدداً اصلاح شده است.
سازگاری چند پلتفرمی کاتلین چرخه حیات
APIهای اصلی Lifecycle در 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
منتقل میکند و یک مصنوع Android را ارسال میکند که با پشتیبانی چند پلتفرمیandroidx.compose
مطابقت دارد.
سازگاری چند پلتفرمی ViewModel Kotlin
مصنوع lifecycle-viewmodel
و APIهایی مانند ViewModel
، ViewModelStore
، ViewModelStoreOwner
، و ViewModelProvider
اکنون در مصنوعات سازگار با Kotlin Multiplatform ارسال می شوند.
برای تطبیق با این تغییر، روشهایی مانند روشهایی در ViewModelProvider
که java.lang.Class<T>
را انتخاب کردند، اکنون یک متد معادل دارند که یک kotlin.reflect.KClass<T>
میگیرد.
سازگاری باینری در Android حفظ شده است، اما در مقایسه سطح API Android با سطح API مشترک، چند تغییر قابل توجه وجود دارد:
- ساختن یک نمونه
ViewModelProvider
اکنون از طریق متدهایViewModelProvider.create()
انجام می شود نه اینکه مستقیما سازنده آن را فراخوانی کند. -
ViewModelProvider.NewInstanceFactory
وViewModelProvider.AndroidViewModelFactory
فقط در Android در دسترس هستند.- سفارشی Factories توصیه می شود از
ViewModelProvider.Factory
گسترش یافته و از روشcreate
استفاده کنند که یکCreationExtras
می گیرد یا ازviewModelFactory
Kotlin DSL استفاده می کند.
- سفارشی Factories توصیه می شود از
- استفاده از
ViewModelProvider
بدون کارخانه سفارشی در پلتفرمهای غیر JVM منجر بهUnsupportedOperationException
میشود. در پلتفرمهای JVM، اگر کارخانه سفارشی ارائه نشود، سازگاری با استفاده از سازنده ViewModel بدون args حفظ میشود. -
viewModelScope
به یکEmptyCoroutineContext
در پلتفرم هایی کهDispatchers.Main
در دسترس نیست (مثلاً لینوکس) بازگشتی خواهد داشت.
مصنوعات تحت تاثیر:
-
lifecycle-viewmodel
اکثر API ها را بهcommon
منتقل می کند و علاوه بر اندروید از jvm و iOS نیز پشتیبانی می کند. -
lifecycle-viewmodel-ktx
اکنون خالی است و همه APIها بهlifecycle-viewmodel
منتقل می شوند. -
lifecycle-viewmodel-compose
همه APIها را بهcommon
منتقل میکند و یک مصنوع Android را ارسال میکند، که با پشتیبانی چند پلتفرمیandroidx.compose
مطابقت دارد.
تغییرات رفتار
-
InitializerViewModelFactory
(شامل تابع سازندهviewModelFactory
) اکنون یکIllegalArgumentException
ایجاد می کند اگر یکinitializer
با همانclazz: KClass<VM : ViewModel>
قبلاً اضافه شده باشد. ( IC3a36 )
مسائل شناخته شده
-
lifecycle-*:2.8.0
به حداقل نسخه Compose 1.7.0-alpha05 ( b/336842920 ) نیاز دارد.
نسخه 2.8.0-rc01
1 مه 2024
androidx.lifecycle:lifecycle-*:2.8.0-rc01
منتشر شد. نسخه 2.8.0-rc01 حاوی این commit ها است.
رفع اشکال
- مشکلی که در آن نمایه خط پایه برای کلاسهای
lifecycle-common
به درستی بستهبندی نشده بود، برطرف شد. اینها اکنون در AARlifecycle-runtime
بسته بندی شده اند. ( aosp/3038274 , b/322382422 ) - اصلاح یک تغییر سفارش ناخواسته در نحوه پاک شدن نمونه های
AutoCloseable
متصل به ViewModel - ترتیب قبلیaddCloseable(String, AutoCloseable)
و سپسaddClosable(AutoCloseable)
و سپسonCleared()
بازیابی شده است. ( aosp/3041632 ) - رفتار ایجاد پیش فرض را برای
viewModelScope
برای محیط های Native و JVM Desktop بهبود دهید. ( aosp/3039221 )
مشارکت خارجی
- با تشکر از Victor Kropp برای بهبود بررسی موضوع اصلی در JVM Desktop. ( aosp/3037116 )
نسخه 2.8.0-beta01
17 آوریل 2024
androidx.lifecycle:lifecycle-*:2.8.0-beta01
منتشر شد. نسخه 2.8.0-beta01 حاوی این تعهدات است.
ویژگی های جدید
- مصنوع
lifecycle-runtime-compose
اکنون با Kotlin Multiplatform سازگار است، کد آن را بهcommon
منتقل میکند و یک مصنوع Android را ارسال میکند، مطابق با پشتیبانی از multiplatform برایandroidx.compose
. ( If7a71 , I4f4a0 , b/331769623 )
نسخه 2.8.0-alpha04
3 آوریل 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha04
منتشر شد. نسخه 2.8.0-alpha04 حاوی این commit ها است.
ویژگی های جدید
- مصنوع
lifecycle-viewmodel-compose
اکنون با Kotlin Multiplatform سازگار است، کد آن را بهcommon
منتقل میکند و یک مصنوع Android را ارسال میکند، که با پشتیبانی چندپلتفرمیandroidx.compose
مطابقت دارد. برای تطبیق با این تغییر، روش ComposableviewModel
اکنون یکKClass
علاوه بر یکjava.lang.Class
می پذیرد. ( b/330323282 )
رفع اشکال
-
NullSafeMutableLiveData
برای جلوگیری از بسیاری از موارد مثبت کاذب مجدداً اصلاح شده است. ( I2d8c1 ، Iafb18 ، I03463 ، I7ecef )
به روز رسانی وابستگی
- مصنوع
lifecycle-viewmodel-compose
اکنون به Compose 1.6.0 بستگی دارد. - چرخه حیات اکنون به Profile Installer 1.3.1 بستگی دارد.
نسخه 2.8.0-alpha03
20 مارس 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha03
منتشر شد. نسخه 2.8.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
ViewModel.viewModelScope
اکنون یک پارامتر سازنده قابل لغو است که به شما امکان می دهد توزیع کننده و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) }
سازگاری چند پلتفرمی Kotlin
مصنوع lifecycle-viewmodel
و APIهایی مانند ViewModel
، ViewModelStore
، ViewModelStoreOwner
، و ViewModelProvider
اکنون در مصنوعات سازگار با Kotlin Multiplatform ارسال می شوند. ( b/214568825 )
برای تطبیق با این تغییر، روشهایی مانند روشهایی در ViewModelProvider
که java.lang.Class<T>
را انتخاب کردند، اکنون یک متد معادل دارند که یک kotlin.reflect.KClass<T>
میگیرد.
سازگاری باینری در Android حفظ شده است، اما در مقایسه سطح API Android با سطح API مشترک، چند تغییر قابل توجه وجود دارد:
- ساختن یک نمونه
ViewModelProvider
اکنون از طریق متدهایViewModelProvider.create()
انجام می شود نه اینکه مستقیما سازنده آن را فراخوانی کند. -
ViewModelProvider.NewInstanceFactory
وViewModelProvider.AndroidViewModelFactory
فقط در Android در دسترس هستند.- سفارشی Factories توصیه می شود از
ViewModelProvider.Factory
گسترش یافته و از روشcreate
استفاده کنند که یکCreationExtras
می گیرد یا ازviewModelFactory
Kotlin DSL استفاده می کند.
- سفارشی Factories توصیه می شود از
- استفاده از
ViewModelProvider
بدون کارخانه سفارشی در پلتفرمهای غیر JVM منجر بهUnsupportedOperationException
میشود. در پلتفرمهای JVM، اگر کارخانه سفارشی ارائه نشود، سازگاری با استفاده از سازنده ViewModel بدون args حفظ میشود. -
viewModelScope
به یکEmptyCoroutineContext
در پلتفرم هایی کهDispatchers.Main
در دسترس نیست (مثلاً لینوکس) بازگشتی خواهد داشت.
تغییرات رفتار
-
InitializerViewModelFactory
(شامل تابع سازندهviewModelFactory
) اکنون یکIllegalArgumentException
ایجاد می کند اگر یکinitializer
با همانclazz: KClass<VM : ViewModel>
قبلاً اضافه شده باشد. ( IC3a36 )
رفع اشکال
-
ViewModel.getCloseable
اکنون کلیدهای تکراری را کنترل می کند: اگرkey
قبلاً دارای یک منبعAutoCloseable
مرتبط با آن باشد، منبع قدیمی جایگزین شده و بلافاصله بسته می شود. ( IBeb67 ) - دسترسی به
viewModelScope
یکViewModel
در حال حاضر امن است. ( If4766 , b/322407038 )
مشارکت خارجی
-
LocalLifecycleOwner
از Compose UI به lifecycle-runtime-compose منتقل شد تا API های کمکی مبتنی بر Compose آن بتوانند خارج از Compose UI استفاده شوند. با تشکر از جیک وارتون برای کمک. ( I6c41b , b/328263448 )
نسخه 2.8.0-alpha02
21 فوریه 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha02
منتشر شد. نسخه 2.8.0-alpha02 حاوی این commit ها است.
ویژگی های جدید
- APIهای
dropUnlessResumed
وdropUnlessStarted
اضافه شدهاند که به شما امکان میدهند کلیک یا رویدادهای دیگری را که حتی پس از سقوطLifecycleOwner
به زیرLifecycle.State
رخ میدهند، رها کنید. به عنوان مثال، این می تواند با Navigation Compose برای جلوگیری از مدیریت رویدادهای کلیک پس از اینکه انتقال به صفحه دیگری از قبل شروع شده است استفاده شود:onClick: () -> Unit = dropUnlessResumed { navController.navigate(NEW_SCREEN) }
( Icba83 , b/317230685 )
تبدیل کاتلین
-
ViewModel
اکنون در Kotlin نوشته شده است ( I16f26 , b/214568825 ) - پسوندهای
lifecycle-viewmodel-ktx
kotlin اکنون به ماژول چرخه حیات پایه منتقل شدهاند. ( Id787b , b/274800183 ) - الحاقات
lifecycle-runtime-ktx
kotlin اکنون به ماژول چرخه حیات پایه منتقل شده اند. ( IC3686 , b/274800183 ) - پسوندهای
lifecycle-livedata-core-ktx
kotlin اکنون به ماژول چرخه حیات پایه منتقل شدهاند. ( I54a3d , b/274800183 )
سازگاری چند پلتفرمی Kotlin
- APIهای اصلی Lifecycle در
Lifecycle
،LifecycleOwner
،LifecycleObserver
،Lifecycle.State
،Lifecycle.Event
، وLifecycleRegistry
اکنون در مصنوعات سازگار با Kotlin Multiplatform ارسال می شوند. ( b/317249252 )
تغییرات API
- فراخوانی
LifecycleStartEffect
وLifecycleResumeEffect
بدون کلید اکنون یک خطا است و از همان قراردادDisposableEffect
API پیروی می کند که این APIها منعکس می کنند. ( Ib0e0c , b/323518079 ) -
ViewModel
اکنون ازAutoCloseable
به جایCloseable
استفاده می کند. این یک تغییر سازگار با عقب است. ( I27f8e , b/214568825 ) -
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)
به نفعLiveData.toPublisher(lifecycleOwner)
منسوخ شد. ( Iabe29 , b/262623005 )
مشارکت خارجی
- از ایوان ماتکوف از Jetbrains برای کمک به انتقال Lifecycle به چند پلتفرم Kotlin تشکر می کنیم. ( aosp/2926690 ، I0c5ac ، If445d )
نسخه 2.8.0-alpha01
24 ژانویه 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha01
منتشر شد. نسخه 2.8.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
-
ViewModel
اکنون از افزودن اشیایCloseable
باkey
پشتیبانی می کند که امکان بازیابی آنها را از طریقgetCloseable()
فراهم می کند. ( I3cf63 )
نسخه 2.7
نسخه 2.7.0
10 ژانویه 2024
androidx.lifecycle:lifecycle-*:2.7.0
منتشر شد. نسخه 2.7.0 حاوی این commit ها است.
تغییرات مهم از 2.6.0
-
TestLifecycleOwner
اکنون یک تابع تعلیقsetCurrentState()
را شامل می شود که تضمین می کند که تغییر حالت و تمام تماس هایLifecycleObserver
قبل از بازگشت کامل می شود. قابلتوجه، برخلاف تنظیم مستقیم ویژگیcurrentState
، این ویژگیrunBlocking
استفاده نمیکند و استفاده از آن را در برنامههای معمولی مانند آنچه توسطrunTest
ارائه میکند، ایمن میسازد. - پسوندهای
LiveData
map
وswitchMap
اکنون رفتارdistinctUntilChanged
را منعکس میکنند - اگرLiveData
دارایvalue
تنظیم شده باشد، تابعmap
/switchMap
فوراً برای پر کردنvalue
LiveData
برگشتی فراخوانی میشود. این تضمین میکند که مقدار اولیه به عنوان بخشی از اولین ترکیب تنظیم میشود (هنگامی که باobserveAsState()
) استفاده میشود، اما رفتار مشاهده را تغییر نمیدهد - مقادیر بهروزرسانیها از منبعLiveData
فقط زمانی اعمال میشوند که شروع به مشاهدهLiveData
کنید. - این نسخه مشکلی را برطرف میکند که در آن
SavedStateHandle
کلاسهای سفارشیParcelable
را پس از مرگ فرآیند و بازیابی به درستی بازیابی نمیکند. با توجه به اطلاعات تایپی که توسط فریمورک اندروید از دست میرود، آرایههای Parcelables سفارشی به کار بیشتری نیاز دارند (ایجاد دستی آرایهای تایپشده از نوع مناسب) و مستنداتget
،getLiveData
وgetStateFlow
اکنون بهطور خاص این محدودیت را فراخوانی میکنند. - قوانین حفظ حفاظت مرتبط با
LifecycleObserver
حذف شده است. این بدان معنی است که کد محافظت شده ای که می خواهد از API ها از طریق بازتاب استفاده کند (مانند استفاده از حاشیه نویسی@OnLifecycleEvent
که مدت هاست منسوخ شده است) باید قوانین حفظ خود را برای مورد استفاده خاص خود ارائه دهد.
قابلیت مشاهده رویداد چرخه حیات
- به عنوان جایگزینی برای استفاده از
LifecycleEventObserver
، اکنون می توانید یکFlow
ofLifecycle.Event
از طریق متد توسعهLifecycle.asFlow()
مشاهده کنید. - کاربران Jetpack Compose اکنون می توانند از
LifecycleEventEffect
برای اجرای عوارض جانبی Compose بر اساسLifecycle.Event
استفاده کنند.
@Composable
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
viewModel.refreshData()
}
// …
}
- کاربران Jetpack Compose میتوانند از
LifecycleStartEffect
وLifecycleResumeEffect
برای رسیدگی به جفت رویدادها استفاده کنند - به ترتیب شروع به متوقف شدن و از سرگیری تا توقف موقت شدند. این API منعکس کننده API موجود درDisposableEffect
است و برای مواردی مناسب است که تغییری که هنگام بالا رفتن حالت ایجاد میشود، باید هنگام بازگشت به پایین معکوس شود.
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
LifecycleStartEffect(viewModel) {
val timeTracking = viewModel.startTrackingTimeOnScreen()
onStopOrDispose {
timeTracking.stopTrackingTimeOnScreen()
}
}
// …
}
برای اطلاعات بیشتر به اجرای کد روی رویدادهای چرخه حیات مراجعه کنید.
قابلیت مشاهده وضعیت چرخه حیات
- اکنون میتوان
Lifecycle.State
فعلی را از طریق ویژگیLifecycle.currentStateFlow
مشاهده کرد، که یکStateFlow
برمیگرداند که در آنvalue
Lifecycle.State
فعلی است. - کاربران Jetpack Compose می توانند از پسوند
Lifecycle.currentStateAsState()
برای نمایش مستقیمLifecycle.State
به عنوان ComposeState
استفاده کنند. این معادل (و یک جایگزین کوتاهتر) برایlifecycle.currentStateFlow.collectAsState()
است.
برای اطلاعات بیشتر به جمع آوری وضعیت چرخه حیات با جریان ها مراجعه کنید.
نسخه 2.7.0-rc02
13 دسامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-rc02
منتشر شد. نسخه 2.7.0-rc02 حاوی این commit ها است.
رفع اشکال
- مشکلی را که در آن
SavedStateHandle
به درستی کلاسهایParcelable
سفارشی را پس از مرگ فرآیند و بازیابی بازیابی نمیکرد، برطرف شد. با توجه به اطلاعات تایپی که توسط فریمورک اندروید از دست میرود، آرایههای Parcelables سفارشی به کار بیشتری نیاز دارند (ایجاد دستی آرایهای تایپشده از نوع مناسب) و مستنداتget
،getLiveData
وgetStateFlow
اکنون بهطور خاص این محدودیت را فراخوانی میکنند. ( I0b55a )
نسخه 2.7.0-rc01
15 نوامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-rc01
منتشر شد. نسخه 2.7.0-rc01 حاوی این commit ها است.
رفع اشکال
-
LifecycleStartEffect
وLifecycleResumeEffect
اکنون در صورت تغییرLifecycleOwner
، بلوک اثر را به درستی از بین می برند و دوباره ایجاد می کنند. ( Ia25c6 )
نسخه 2.7.0-beta01
1 نوامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-beta01
بدون هیچ تغییری منتشر شد. نسخه 2.7.0-beta01 حاوی این تعهدات است.
- یک نسخه بتا، بدون تغییر عمده در این نسخه منتشر شده.
نسخه 2.7.0-alpha03
18 اکتبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha03
منتشر شد. نسخه 2.7.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
-
lifecycle-runtime-testing
اکنون حاوی یک بررسی Lint جدید است تا از تنظیمLifecycle.State
TestLifecycleOwner
با استفاده از فیلدcurrentState
در داخل یک برنامه اجتناب شود. بررسی Lint اکنونsetCurrentState
را تعلیق می کند که اجازه می دهد تاLifecycle.State
را بدون مسدود کردن تنظیم کنید. ( Icf728 , b/297880630 )
رفع اشکال
- مشکلی در
LiveData.switchMap
برطرف شد که در آن بازگرداندن همان نمونهLiveData
هم در تماس اولیه و هم در تماس بعدی، از اضافه شدن نمونهLiveData
به عنوان منبع جلوگیری میکرد. ( Ibedcba7 )
نسخه 2.7.0-alpha02
6 سپتامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha02
منتشر شد. نسخه 2.7.0-alpha02 حاوی این commit ها است.
ویژگی های جدید
-
TestLifecycleOwner
اکنون شامل تابع تعلیقsetCurrentState()
است تا به کاربران این امکان را بدهد که ازTestLifecycleOwner
از درون برنامهای مانند آنچه توسطrunTest
ارائه شده است استفاده کنند. ( I329de , b/259344129 )
تغییرات API
- تمام فایلهای ماژولهای
lifecycle-livedata-ktx
به ماژول اصلیlifecycle-livedata
منتقل شدهاند. ( I10c6f , b/274800183 )
تغییرات رفتار
- پسوندهای
LiveData.map()
وLiveData.switchMap()
اکنونvalue
LiveData
برگشتی را در صورتی کهLiveData
قبلی مقداری روی آن تنظیم شده باشد، تعیین میکند، و اطمینان حاصل میکند که استفاده از LiveData بهدستآمده در Jetpack Compose حالت درستی را در ترکیب اولیه دارد. ( I91d2b , b/269479952 ) - در صورتی که
ViewModel
قبلاً باonCleared()
تماس گرفته باشد، اکنونaddCloseable()
ViewModel
بلافاصلهCloseable
می بندد. ( I4712e , b/280294730 )
رفع اشکال
- از Lifecycle
2.6.2
: مشکلی را برطرف کرد که در آنSavedStateHandle
پس از مرگ فرآیند به درستی بازیابی نمی شد، در صورت بازیابی وضعیت،save()
بدون ذخیره واقعی حالت درSavedStateRegistry
والد فراخوانی شد و سپس وضعیت دوباره بازیابی شد. این کار تعامل بینrememberSaveable
وNavHost
Navigation Compose را برطرف می کند. ( aosp/2729289 )
نسخه 2.7.0-alpha01
26 جولای 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha01
منتشر شد. نسخه 2.7.0-alpha01 حاوی این commit ها است.
تغییرات API
-
Lifecycle.State
اکنون از طریقLifecycle.currentStateFlow
قابل مشاهده است، که یکStateFlow
برمیگرداند که در آنvalue
Lifecycle.State
فعلی است. ( Ib212d , b/209684871 ) -
Lifecycle.Event
s اکنون می تواند به عنوان یکFlow
باLifecycle.asFlow().
( If2c0f , b/176311030 ) -
LifecycleResumeEffect
API برای اجرای ComposeSideEffect
بر اساس تماسهای رویدادLifecycle.Event.ON_RESUME
وLifecycle.Event.ON_PAUSE
اضافه شده است. ( I60386 , b/235529345 ) -
LifecycleStartEffect
API برای اجرای ComposeSideEffect
بر اساس تماسهای رویدادLifecycle.Event.ON_START
وLifecycle.Event.ON_STOP
اضافه شده است. ( I5a8d1 , b/235529345 ) -
LifecycleEventEffect
API برای اجرای ComposeSideEffect
بر اساسLifecycle.Event
اضافه شده است. ( Ic9794 , b/235529345 ) - پسوند
Lifecycle.collectAsState()
برای نمایش مستقیمLifecycle.State
به عنوان ComposeState
اضافه شده است. این معادل (و یک جایگزین کوتاهتر) برایlifecycle.currentStateFlow.collectAsState()
است. ( I11015 , b/235529345 )
رفع اشکال
- پسوند
LiveData.distinctUntilChanged()
اکنونvalue
LiveData
برگشتی را در صورتی کهLiveData
قبلی مقداری روی آن تنظیم کرده باشد، تعیین می کند. این رفتار مشاهده را تغییر نمی دهد - مقادیر به روز شده از منبعLiveData
فقط زمانی اعمال می شود که مشاهدهLiveData
برگردانده شده ازdistinctUntilChanged()
را شروع کنید. ( IB482f ) - قوانین حفظ حفاظت مرتبط با
LifecycleObserver
حذف شده است. این بدان معنی است که کد محافظت شده ای که می خواهد از API ها از طریق بازتاب استفاده کند، باید قوانین نگهداری خود را برای مورد استفاده خاص خود ارائه دهد. ( Ia12fd )
نسخه 2.6
نسخه 2.6.2
6 سپتامبر 2023
androidx.lifecycle:lifecycle-*:2.6.2
منتشر شد. نسخه 2.6.2 حاوی این commit ها است.
رفع اشکال
- مشکلی را برطرف کرد که در آن
SavedStateHandle
پس از مرگ پردازش، در صورت بازیابی وضعیت، به درستی بازیابی نمیشد،save()
بدون ذخیره واقعی حالت درSavedStateRegistry
والد فراخوانی شد و سپس وضعیت دوباره بازیابی شد. این کار تعامل بینrememberSaveable
وNavHost
Navigation Compose را برطرف می کند. ( aosp/2729289 )
نسخه 2.6.1
22 مارس 2023
androidx.lifecycle:lifecycle-*:2.6.1
منتشر شد. نسخه 2.6.1 حاوی این commit ها است.
به روز رسانی های وابستگی
-
lifecycle-viewmodel-savedstate
اکنون به SavedState1.2.1
بستگی دارد. ( cd7251 ) - چرخه حیات اکنون به ProfileInstaller
1.3.0
بستگی دارد. ( f9d30b )
نسخه 2.6.0
8 مارس 2023
androidx.lifecycle:lifecycle-*:2.6.0
منتشر شد. نسخه 2.6.0 حاوی این commit ها است.
تغییرات مهم از 2.5.0
-
LiveData
اکنون دارای ویژگیisInitialized
جدیدی است که نشان میدهد آیا یک مقدار صریح رویLiveData
تنظیم شده است یا خیر، به شما این امکان را میدهد که بینliveData.value
کهnull
را برمیگرداند تمایز قائل شوید زیرا هیچ مقداری تا کنون تنظیم نشده است یا یک مقدارnull
صریح. -
MediatorLiveData
اکنون شامل یک سازنده برای تنظیم مقدار اولیه است. - یک برنامه افزودنی جدید در
StateFlow
وFlow
ofcollectAsStateWithLifecycle()
اضافه شده است که از جریان ها جمع آوری می شود و آخرین مقدار آن را به عنوان Compose State به شیوه ای آگاه از چرخه حیات نشان می دهد. - روشهای
Lifecycle.launchWhenX
وLifecycle.whenX
منسوخ شدهاند، زیرا استفاده از توزیعکننده مکث میتواند در برخی موارد منجر به هدر رفتن منابع شود. توصیه می شود ازLifecycle.repeatOnLifecycle
استفاده کنید. برای اطلاعات بیشتر در مورد تعلیق یک بار کار، لطفاً به این توضیح در مورد اینکه چرا این کار ذاتاً ناامن است، مراجعه کنید. - تبدیل Kotlin - تعداد زیادی از کلاس های Lifecycle به Kotlin تبدیل شده اند. همه کلاس های تبدیل شده هنوز سازگاری باینری خود را با نسخه های قبلی حفظ می کنند. کلاس های زیر دارای تغییرات ناسازگار منبع برای کلاس های نوشته شده در Kotlin هستند:
ViewTreeLifecycleOwner
،LiveDataReactiveStreams
،HasDefaultViewModelProviderFactory
،ViewTreeViewModelStoreOwner
،Transformations
،ViewModelStoreOwner
،LifecycleOwner
جدول زیر تبدیل های منبع را برای نسخه جدید چرخه حیات ارائه می دهد.
چرخه حیات 2.5 | چرخه زندگی 2.5 (KTX) | چرخه حیات 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 |
- پوچپذیری متد
onChanged
یکObserver
که در Kotlin ایجاد شده است، اکنون با پوچپذیری نوع عمومی مطابقت دارد. اگر می خواهیدObserver.onChanged()
یک نوع nullable را بپذیرد، بایدObserver
را با یک نوع nullable نمونه سازی کنید. - این کلاسها نیز به Kotlin تبدیل شدند، اما سازگار با منبع باقی میمانند:
DefaultLifecycleObserver
،LifecycleEventObserver
،Lifecycle
،LifecycleRegistry
ServiceLifecycleDispatcher
LifecycleObserver
،ViewModelStore
،AndroidViewModel
،AbstractSavedStateViewModelFactory
،LifecycleService
، وProcessLifecycleOwner
نسخه 2.6.0-rc01
22 فوریه 2023
androidx.lifecycle:lifecycle-*:2.6.0-rc01
منتشر شد. نسخه 2.6.0-rc01 حاوی این commit ها است.
رفع اشکال
- پسوند
LiveData.distinctUntilChanged()
اکنونvalue
LiveData
برگشتی را در صورتی کهLiveData
قبلی مقداری روی آن تنظیم کرده باشد، تعیین می کند. این رفتار مشاهده را تغییر نمی دهد - مقادیر به روز شده از منبعLiveData
فقط زمانی اعمال می شود که مشاهدهLiveData
برگردانده شده ازdistinctUntilChanged()
را شروع کنید. ( IB482f )
نسخه 2.6.0-beta01
8 فوریه 2023
androidx.lifecycle:lifecycle-*:2.6.0-beta01
منتشر شد. نسخه 2.6.0-beta01 حاوی این تعهدات است.
تبدیل کاتلین
-
LifecycleOwner
اکنون در Kotlin نوشته شده است. این یک تغییر منبع ناسازگار برای کلاس های نوشته شده در Kotlin است - آنها اکنون باید ویژگیlifecycle
را به جای اجرای تابعgetLifecycle()
قبلی لغو کنند. ( I75b4b , b/240298691 ) -
ViewModelStoreOwner
اکنون در Kotlin است. این یک تغییر ناسازگار منبع برای کلاسهای نوشته شده در کوتلین است - آنها اکنون باید به جای اجرای عملکرد قبلیgetViewModelStore()
، از ویژگیviewModelStore
غلبه کنند. ( i86409 ، b/240298691 ) - پسوند Kotlin در
LifecycleOwner
که زمینهlifecycleScope
فراهم می کند ، از آثارlifecycle-common
ازlifecycle-runtime-ktx
منتقل شده است. ( i41d78 ، b/240298691 ) - پسوند Kotlin در
Lifecycle
که زمینهcoroutineScope
را فراهم می کند ، از آثارlifecycle-common
ازlifecycle-runtime-ktx
منتقل شده است. ( IABB91 ، b/240298691 )
نسخه 2.6.0-alpha05
25 ژانویه 2023
androidx.lifecycle:lifecycle-*:2.6.0-alpha05
منتشر می شود. نسخه 2.6.0-alpha05 شامل این تعهدات است.
تبدیل کوتلین
-
Transformations
اکنون در کوتلین نوشته شده است. این یک تغییر ناسازگار منبع برای آن دسته از کلاسهای نوشته شده در کوتلین است که به طور مستقیم از نحو مانندTransformations.map
استفاده می کردند. MAP-کد KOTLIN اکنون باید از نحو روش پسوند Kotlin استفاده کند که قبلاً فقط هنگام استفاده ازlifecycle-livedata-ktx
در دسترس بود. هنگام استفاده از زبان برنامه نویسی جاوا ، نسخه های این روش هایی که از یک روشandroidx.arch.core.util.Function
استفاده می کنند ، مستهلک می شوند و با نسخه هایی کهFunction1
Kotlin1 را دارند جایگزین می شوند. این تغییر سازگاری باینری را حفظ می کند. ( i8e14f ) -
ViewTreeViewModelStoreOwner
اکنون در کوتلین نوشته شده است. این یک تغییر ناسازگار منبع برای آن دسته از کلاسهای نوشته شده در کوتلین است - اکنون باید به طور مستقیم از روشهای پسوند Kotlin درView
androidx.lifecycle.setViewTreeViewModelStoreOwner
وandroidx.lifecycle.findViewTreeViewModelStoreOwner
استفاده کنید و از آن استفاده کنید تا یک مالک قبلی را پیدا کرده و پیدا کنید. این سازگار با دودویی است و برای پیاده سازی هایی که به زبان برنامه نویسی جاوا نوشته شده است سازگار است. ( IA06D8 ، IB22D8 ، B/240298691 ) - رابط
HasDefaultViewModelProviderFactory
اکنون در کوتلین نوشته شده است. این یک تغییر ناسازگار منبع برای کلاسهای نوشته شده در کوتلین است - آنها اکنون باید به جای اجرای توابع مربوطه ،defaultViewModelProviderFactory
وdefaultViewModelCreationExtras
را نادیده بگیرند. ( IAED9C ، B/240298691 ) -
Observer
اکنون در کوتلین نوشته شده است. روشonChanged()
آن اکنون ازvalue
نام برای پارامتر خود استفاده می کند. ( IFFEF2 ، I4995E ، B/240298691 ) -
AndroidViewModel
،AbstractSavedStateViewModelFactory
،LifecycleService
،ServiceLifecycleDispatcher
وProcessLifecycleOwner
اکنون در Kotlin ( I2E7771 ، Ibae40 ، I160D7 ، I08884 ، I160D7 ، I08884 ، I1CDA7 ، B/2402988698869698696986988696988698698
نسخه 2.6.0-alpha04
11 ژانویه 2023
androidx.lifecycle:lifecycle-*:2.6.0-alpha04
منتشر می شود. نسخه 2.6.0-alpha04 شامل این تعهدات است.
ویژگی های جدید
-
LiveData
اکنون شامل یک خاصیتisInitialized
است که نشان می دهد آیا یک مقدار صریح تاکنون درLiveData
تعیین شده است ، به شما امکان می دهد بینliveData.value
بازگشتnull
تشخیص دهید زیرا هیچ مقدار تعیین نشده است یا یک مقدارnull
صریح. ( IBD018 )
تغییرات API
- API های
collectAsStateWithLifecycle()
API ازlifecycle-runtime-compose
دیگر در وضعیت آزمایشی نیستند. ( I09D42 ، B/258835424 ) - روشهای
Lifecycle.launchWhenX
وLifecycle.whenX
روشهای Whenx از بین رفته اند زیرا استفاده از یک توزیع کننده مکث می تواند در برخی موارد منجر به هدر رفتن منابع شود. توصیه می شود ازLifecycle.repeatOnLifecycle
استفاده کنید. RepeatonLifecycle. ( IAFC54 ، B/248302832 )
تبدیل کوتلین
-
ViewTreeLifecycleOwner
اکنون در کوتلین نوشته شده است. این یک تغییر ناسازگار منبع برای آن دسته از کلاسهای نوشته شده در کوتلین است - اکنون باید مستقیماً روشهای پسوند Kotlin را باView
بهandroidx.lifecycle.setViewTreeLifecycleOwner
وandroidx.lifecycle.findViewTreeLifecycleOwner
برای تنظیم و پیدا کردن یک مالک قبلی تنظیم کنید. این جایگزین پسوند Kotlin قبلی درlifecycle-runtime-ktx
می شود. این سازگار با دودویی است و برای پیاده سازی هایی که به زبان برنامه نویسی جاوا نوشته شده است سازگار است. ( i8a77a ، i5234e ، b/240298691 ) -
LiveDataReactiveStreams
اکنون در کوتلین نوشته شده است. پسوندهای Kotlin که قبلاً درlifecycle-reactivestreams-ktx
به ماژولlifecycle-reactivestreams
منتقل شده و به سطح اصلی برای کد نوشته شده در کوتلین تبدیل شده اند. اگر قبلاً از API های روش پسوند Kotlin استفاده نمی کردید ، این یک تغییر ناسازگار برای کد نوشته شده در Kotlin است. ( I2B1B9 ، I95D22 ، B/240298691 ) -
DefaultLifecycleObserver
,LifecycleEventObserver
,Lifecycle
,LifecycleRegistry
,LifecycleObserver
, andViewModelStore
are now written in Kotlin ( Iadffd , ( I60034 , I8c52c , I9593d , I01fe1 , I59a23 , b/240298691 )
رفع اشکال
-
SavedStateHandle
هنگام فراخوانیget()
با نوع کلاس نادرست دیگر با یکClassCastException
خراب نمی شود. ( i6ae7c )
نسخه 2.6.0-alpha03
24 اکتبر 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha03
منتشر می شود. نسخه 2.6.0-alpha03 حاوی این commit ها است.
رفع اشکال
- مسئله ای را با محدودیت بین ماژول های مختلف چرخه عمر که مطابق آنچه در نظر گرفته شده کار نمی کنند ، برطرف کرد. ( i18d0d ، b/249686765 )
- خطاهای پرتاب شده توسط
LifecycleRegistry.moveToState()
اکنون شامل یک پیام خطای مفیدتر است که به توسعه دهندگان از مؤلفه که باعث خطا می شود ، اطلاع می دهد. ( IDF4B2 ، B/244910446 )
نسخه 2.6.0-alpha02
7 سپتامبر 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha02
منتشر می شود. نسخه 2.6.0-alpha02 حاوی این commit ها است.
تغییرات API
-
MediatorLiveData
اکنون شامل یک سازنده برای تعیین مقدار اولیه است. ( IB6CC5 ، B/151244085 )
رفع اشکال
- در حال حاضر مصنوعات
Lifecycle
شامل محدودیت هایی است که اطمینان حاصل می کند که تمام مصنوعات چرخه عمر وابسته به همان نسخه از همان نسخه استفاده می کنند ، به طور خودکار سایر وابستگی ها را هنگام به روزرسانی به روز می کنند. b/242871265 -
FlowLiveData.asFlow()
اکنون به جای استفاده از اجرایChannel
خود برای اطمینان از امنیت موضوع و حفظ زمینه ، یکcallbackFlow
ایجاد می کند. ( i4a8b2 ، b/200596935 ) - عملکرد
asLiveData
FlowLiveData
اکنون هنگام ایجاد شیء جدیدLiveData
، مقدار اولیه یکStateFlow
را حفظ می کند. ( i3f530 ، b/157380488 ) - از Lifecycle
2.5.1
: پیاده سازی های سفارشیAndroidViewModelFactory
اکنون به طور صحیح عملکردcreate(modelClass)
را هنگام استفاده از سازنده حالت باLifecycle
2.4+ ( I5B315 ، B/238011621 ) فراخوانی می کند.
نسخه 2.6.0-alpha01
29 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha01
منتشر می شود. نسخه 2.6.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
- افزودنی جدید در
StateFlow
وFlow
collectAsStateWithLifecycle
که از جریان جمع می شود و آخرین مقدار آن را به عنوان حالت آهنگسازی به روش آگاه از چرخه عمر نشان می دهد. جریان جمع آوری می شود و انتشار جدید بر روی مقدار حالت تنظیم می شود که چرخه عمر حداقل در یکLifecycle.State
خاص باشد. هنگامی که چرخه عمر زیر آنLifecycle.State
قرار می گیرد. محل ، مجموعه جریان متوقف می شود و مقدار حالت به روز نمی شود. ( i1856e ، b/230557927 )
نسخه 2.5
نسخه 2.5.1
27 جولای 2022
androidx.lifecycle:lifecycle-*:2.5.1
منتشر می شود. نسخه 2.5.1 حاوی این commit ها است.
رفع اشکال
- اجرای سفارشی
AndroidViewModelFactory
اکنون به طور صحیح با استفاده از سازندهAndroidViewModelFactory
باLifecycle
2.4+ ، عملکردcreate(modelClass)
را فراخوانی می کند. ( i5b315 ، b/238011621 )
نسخه 2.5.0
29 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.5.0
منتشر می شود. نسخه 2.5.0 شامل این commit ها است.
تغییرات مهم از 2.4.0
SavedStateHandle
اکنون یک APIgetStateFlow()
را ارائه می دهد که یکStateFlow
Kotlin را برای نظارت بر تغییرات ارزش به عنوان جایگزینی برای استفاده ازLiveData
باز می گرداند.ViewModel CreationExtras - هنگام نوشتن یک
ViewModelProvider.Factory
، دیگر نیازی به گسترشAndroidViewModelFactory
یاAbstractSavedStateViewModelFactory
نیست تا به ترتیب دسترسی به یکApplication
یاSavedStateHandle
را بدست آورید. در عوض ، این زمینه ها به هرViewModelProvider.Factory
Subclass به عنوانCreationExtras
از طریق اضافه بار جدیدcreate
:create(Class<T>, CreationExtras)
ارائه می شود. این موارد اضافی به ترتیب توسط فعالیت یا قطعه شما هنگام استفاده از فعالیت1.5.0
و قطعه1.5.0
به طور خودکار ارائه می شود.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-viewmodel
اکنون یکviewModelFactory
Kotlin DSL را فراهم می کند که به شما امکان می دهدViewModelProvider.Factory
را تعریف کنید. از نظر یک یا چند اولیه اولیه لامبدا ، یکی برای هر کلاسViewModel
خاص ، از کارخانه سفارشی شما پشتیبانی می کند ، با استفاده ازCreationExtras
به عنوان منبع اصلی داده ها.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-compose
اکنون یک APIviewModel()
را ارائه می دهد که یک کارخانه Lambda را برای ایجاد یک نمونهViewModel
می گیرد بدون اینکه نیاز به ایجاد یکViewModelProvider.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 یکپارچه سازی Saver را تشکیل می دهد- Artifact
lifecycle-viewmodel-compose
در حال حاضر حاوی API های آزمایشی جدید درSavedStateHandle.saveable
است که بهrememberSaveable
اجازه می دهد مانند رفتار با حمایت ازSavedStateHandle
از «ViewModel فراهم شود.class ListScreenViewModel(handle: SavedStateHandle): ViewModel() { // This value survives both configuration changes and process death and recreation val editMode by handle.saveable { mutableStateOf(false) } }
یک API
addCloseable()
و یک اضافه بار سازنده جدید اضافه کرد که به شما امکان می دهد یک یا چند شیءCloseable
را بهViewModel
اضافه کنید که هنگام پاک شدنViewModel
بدون نیاز به کار دستی درonCleared()
بسته می شود.به عنوان مثال ، برای ایجاد دامنه Coroutine که می توانید به یک ViewModel تزریق کنید ، اما از طریق آزمایش کنترل می کنید ، می توانید یک
CoroutineScope
ایجاد کنید کهCloseable
باشد:class CloseableCoroutineScope( context: CoroutineContext = SupervisorJob() + Dispatchers.Main.immediate ) : Closeable, CoroutineScope { override val coroutineContext: CoroutineContext = context override fun close() { coroutineContext.cancel() } }
که می تواند ضمن حفظ همان عمر
viewModelScope
در سازندهViewModel
شما استفاده شود:class TestScopeViewModel( val customScope: CloseableCoroutineScope = CloseableCoroutineScope() ) : ViewModel(customScope) { // You can now use customScope in the same way as viewModelScope }
تغییر رفتار
- تلاش برای جابجایی
Lifecycle.State
محل ازINITIALIZED
بهDESTROYED
اکنون بدون در نظر گرفتن اینکهLifecycle
دارای یک ناظر متصل است ، همیشه یکIllegalStateException
پرتاب می کند. -
LifecycleRegistry
اکنون هنگام رسیدن به وضعیتDESTROYED
، ناظران خود را پاک می کند.
نسخه 2.5.0-RC02
15 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.5.0-rc02
منتشر می شود. نسخه 2.5.0-RC02 شامل این تعهدات است.
رفع اشکال
-
ViewModelProvider
هنگام مخلوط کردن نسخه های قبلی وابستگی های چرخه عمر کامپایلون با نسخه های 2.5+ دیگر خراب نمی شود. ( i81a66 ، b/230454566 )
نسخه 2.5.0-rc01
11 مه 2022
androidx.lifecycle:lifecycle-*:2.5.0-rc01
منتشر می شود. نسخه 2.5.0-rc01 حاوی این commit ها است.
رفع اشکال
-
MediatorLiveData.addSource()
اکنون به جای انتشار منبعnull
به ناظران ، یک منبعNullPointerException
null
منتقل می کند. ( IBD0FB ، B/123085232 )
نسخه 2.5.0-beta01
20 آوریل 2022
androidx.lifecycle:lifecycle-*:2.5.0-beta01
منتشر می شود. نسخه 2.5.0-beta01 حاوی این تعهدات است.
تغییرات API
- افزود: نمایندگان املاک
SavedStateHandle.saveable
برای استفاده از نام املاک به عنوان کلیدهای برای ادامه وضعیت درSavedStateHandle
( I8BB86 ، B/225014345 )
رفع اشکال
- مسئله ای را برطرف کرد که در آن لانه سازی یک
NavHost
در یکNavHost
دیگری در یک برگه ناوبری غیرقانونی غیرقانونی ، هنگام استفاده از چندین پشته پشت ، منجر بهIllegalStateException
است. ( i11bd5 ، b/228865698 )
نسخه 2.5.0-alpha06
6 آوریل 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha06
منتشر می شود. نسخه 2.5.0-alpha06 شامل این تعهدات است.
ویژگی های جدید
- اضافه بار تجربی
MutableState
را بهSavedStateHandle.saveable
اضافه کنید. قابل حمل برای برابری باrememberSaveable
( I38CFE ، B/224565154 )
تغییرات API
-
CreationExtras
اکنون به جای مهر و موم شده انتزاعی است. ( ib8a7a )
رفع اشکال
- رفع یک
IllegalStateException: Already attached to lifecycleOwner
ناشی ازSavedStateHandleController
متصل شده است. ( i7ea47 ، b/215406268 )
نسخه 2.5.0-alpha05
23 مارس 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha05
منتشر می شود. نسخه 2.5.0-alpha05 شامل این تعهدات است.
ویژگی های جدید
- ماژول
lifecycle-viewmodel-compose
اکنونSavedStateHandleSaver
فراهم می کند ، یک API آزمایشی که مقادیر موجود در یکSavedStateHandle
را تضمین می کند به درستی با همان حالت ذخیره شده ذخیره شده یکپارچه شده است که استفاده هایrememberSaveable
. ( ia88b7 ، b/195689777 )
تغییرات API
- یک مسئله سازگاری با چرخه عمر 2.3 و نسخه های چرخه عمر جدید در جاوا را برطرف کرد. ( i52c8a ، b/219545060 )
رفع اشکال
-
SavedStateViewFactory
اکنون از استفاده ازCreationExtras
پشتیبانی می کند حتی وقتی که با یکSavedStateRegistryOwner
اولیه انجام شد. در صورت ارائه اضافی ، استدلال های اولیه نادیده گرفته می شوند. ( i6c43b ، b/224844583 )
نسخه 2.5.0-alpha04
9 مارس 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha04
منتشر می شود. نسخه 2.5.0-alpha04 شامل این تعهدات است.
تغییرات API
-
SavedStateHandle
اکنون یک APIgetStateFlow()
را ارائه می دهد که یکStateFlow
Kotlin را برای نظارت بر تغییرات ارزش به عنوان جایگزینی برای استفاده ازLiveData
باز می گرداند. ( IAD3AB ، b/178037961 )
نسخه 2.5.0-alpha03
23 فوریه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha03
منتشر می شود. نسخه 2.5.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
- یک API
addCloseable()
و یک اضافه بار سازنده جدید اضافه کرد که به شما امکان می دهد یک یا چند شیءCloseable
را بهViewModel
اضافه کنید که هنگام پاک شدنViewModel
بدون نیاز به کار دستی درonCleared()
بسته می شود. ( i55EA0 ) -
lifecycle-viewmodel
اکنون یکInitializerViewModelFactory
را ارائه می دهد که به شما امکان می دهد Lambda را برای دستیابی به کلاسهای خاصViewModel
اضافه کنید ، با استفاده ازCreationExtras
به عنوان منبع اصلی داده. ( IF58FC ، B/216687549 ) -
lifecycle-viewmodel-compose
اکنون یک APIviewModel()
را ارائه می دهد که یک کارخانه Lambda را برای ایجاد یک نمونهViewModel
می گیرد بدون اینکه نیاز به ایجاد یکViewModelProvider.Factory
داشته باشد. ( I97FBB ، B/216688927 )
تغییرات API
- اکنون می توانید از طریق
ViewModel
از طریقCreationExtras
از طریقlifecycle-viewmodel-compose
ایجاد کنید. ( I08887 ، b/216688927 )
تغییر رفتار
- تلاش برای جابجایی
Lifecycle.State
محل ازINITIALIZED
بهDESTROYED
اکنون بدون در نظر گرفتن اینکهLifecycle
دارای یک ناظر متصل است ، همیشه یکIllegalStateException
پرتاب می کند. ( i7c390 ، b/177924329 ) -
LifecycleRegistry
اکنون هنگام رسیدن به وضعیتDESTROYED
، ناظران خود را پاک می کند. ( i4f8dd ، b/142925860 )
نسخه 2.5.0-alpha02
9 فوریه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha02
منتشر می شود. نسخه 2.5.0-alpha02 حاوی این commit ها است.
تغییرات API
-
SavedStateHandle
وSavedStateViewModelFactory
به کوتلین تبدیل شده اند. این امر باعث افزایش باطل شدن ژنرال ها در هر دو کلاس شده است. ( ib6ce2 ، b/216168263 ، i9647a ، b/177667711 ) - پارامتر عملکرد
LiveData
switchMap
اکنون می تواند خروجی قابل تهی داشته باشد. ( i40396 ، b/132923666 ) - پسوندهای
LiveData
-KTX اکنون با@CheckResult
حاشیه نویسی شده اند تا بتوانند نتیجه را هنگام فراخوانی این توابع استفاده کنند. ( IA0F05 ، B/207325134 )
تغییر رفتار
-
SavedStateHandle
اکنون به درستی پیش فرض Value را ذخیره می کند وقتی که هیچ مقدار برای کلید مشخص شده وجود ندارد. ( i1c6ce ، b/178510877 )
رفع اشکال
- از چرخه عمر
2.4.1
:lifecycle-process
به روز شده به استارتاپ 1.1.1 بستگی دارد تا اطمینان حاصل شود که رفع هایی که مانع ازStartupException
ProcessLifecycleInitializer
می شوند ، به طور پیش فرض در دسترس هستند. ( IB01DF ، B/216490724 ) - اکنون وقتی کلاس های
AndroidViewModel
سفارشی پارامترهایی را به ترتیب اشتباه دارند و سعی در ایجاد یکViewModel
دارند ، یک پیام خطای بهبود یافته وجود دارد. ( i340f7 ، b/177667711 ) - اکنون می توانید با استفاده از
AndroidViewModelFactory
بدون تنظیم یک برنامه ، یک مدل نمایش را از طریقCreationExtras
ایجاد کنید. ( i6ebef ، b/217271656 )
نسخه 2.5.0-alpha01
26 ژانویه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha01
منتشر می شود. نسخه 2.5.0-alpha01 حاوی این commit ها است.
ViewModel CreationExtras
با این نسخه ، ما زمینه را برای بازسازی نحوه ساخت یک ViewModel
در حال انجام هستیم. به جای یک مجموعه سفت و سخت از زیر کلاسهای ViewModelProvider.Factory
که هر یک عملکرد اضافی را اضافه می کند (اجازه می دهد یک پارامتر سازنده Application
از طریق AndroidViewModelFactory
، اجازه دهد یک پارامتر سازنده SavedStateHandle
از طریق SavedStateViewModelFactory
و AbstractSavedStateViewModelFactory
و غیره) در حال حرکت به Water Water Water کارخانه هایی که به یک مفهوم جدید ، CreationExtras
متکی هستند. ( IA7343 ، B/188691010 ، B/188541057 )
با این تغییر ، ViewModelProvider
دیگر تماس های مستقیم به روش قبلی create(Class<T>)
از ViewModelProvider.Factory
انجام نمی دهد. در عوض ، آن را به اضافه بار جدیدی از create
می خواند: create(Class<T>, CreationExtras)
. این بدان معناست که هرگونه اجرای مستقیم از ViewModelProvider.Factory
در حال حاضر به هر یک از این CreationExtras
جدید دسترسی دارد:
-
ViewModelProvider.NewInstanceFactory.VIEW_MODEL_KEY
: اینString
دسترسی به کلید سفارشی را که بهViewModelProvider.get()
منتقل کرده اید ، فراهم می کند. -
ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY
دسترسی به کلاسApplication
را فراهم می کند. -
SavedStateHandleSupport.SAVED_STATE_REGISTRY_OWNER_KEY
دسترسی بهSavedStateRegistryOwner
را که برای ساخت این ViewModel استفاده می شود ، فراهم می کند. -
SavedStateHandleSupport.VIEW_MODEL_STORE_OWNER_KEY
دسترسی بهViewModelStoreOwner
را که برای ساخت این ViewModel استفاده می شود ، فراهم می کند. -
SavedStateHandleSupport.DEFAULT_ARGS_KEY
دسترسی بهBundle
آرگومان هایی را که باید برای ساخت یکSavedStateHandle
استفاده شود ، فراهم می کند.
این موارد اضافی به طور پیش فرض هنگام استفاده از فعالیت 1.5.0-alpha01
، قطعه 1.5.0-alpha01
و ناوبری 2.5.0-alpha01
ارائه می شود. اگر از نسخه قبلی آن کتابخانه ها استفاده می کنید ، CreationExtras
شما خالی خواهد بود - همه زیر کلاسهای موجود ViewModelProvider.Factory
بازنویسی شده است تا از هر دو مسیر ایجاد میراث استفاده شده توسط نسخه های قبلی آن کتابخانه ها و مسیر CreationExtras
که به جلو استفاده می شود ، بازنویسی شود.
این CreationExtras
به شما امکان می دهد یک ViewModelProvider.Factory
بسازید که فقط اطلاعات مورد نیاز شما به هر ViewModel
بدون تکیه بر یک سلسله مراتب دقیق از زیر کلاسهای کارخانه منتقل می کند:
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
}
}
ما از تابع پسوند createSavedStateHandle()
در CreationExtras
از SavedStateHandleSupport
برای ساخت یک SavedStateHandle
فقط برای یک ViewModel که به آن نیاز دارد استفاده می کنیم. ( IA6654 ، b/188541057 )
Custom CreationExtras
می توان با غلبه بر getDefaultViewModelCreationExtras()
در ComponentActivity
یا Fragment
خود ارائه داد ، بنابراین آنها را در دسترس ViewModelProvider.Factory
قرار می دهد. Fective به عنوان ساخته شده در قالب تزریق کمک شده. این موارد اضافی به طور خودکار در هنگام استفاده مستقیم با ViewModelProvider
یا هنگام استفاده by viewModels()
و by activityViewModels()
پسوندهای خاصیت Kotlin در دسترس کارخانه سفارشی شما قرار می گیرند. ( I79F2B ، B/207012584 ، B/207012585 ، B/207012490 )
رفع اشکال
- مسئله ای را برطرف کرد که مقدار پیش فرض ارائه شده به یک
SavedStateHandle
پس از مرگ و تفریح ، حتی اگر به طور خاص ازSavedStateHandle
حذف شود ، دوباره ظاهر می شود. به عنوان یک نتیجه از این ،SavedStateHandle
دیگر مقادیر پیش فرض را ادغام نمی کند و مقادیر را با هم احیا می کند ، در عوض فقط از مقادیر بازسازی شده به عنوان منبع حقیقت استفاده می کند. ( i53a4b )
نسخه 2.4
نسخه 2.4.1
9 فوریه 2022
androidx.lifecycle:lifecycle-*:2.4.1
منتشر می شود. نسخه 2.4.1 حاوی این commit ها است.
رفع اشکال
- پشتوانه از چرخه عمر
2.5.0-alpha01
: مسئله ای را برطرف کرد که مقدار پیش فرض ارائه شده به یکSavedStateHandle
پس از مرگ و تفریح دوباره ظاهر می شود ، حتی اگر به طور خاص ازSavedStateHandle
حذف شود. به عنوان یک نتیجه از این ،SavedStateHandle
دیگر مقادیر پیش فرض را ادغام نمی کند و مقادیر را با هم احیا می کند ، در عوض فقط از مقادیر بازسازی شده به عنوان منبع حقیقت استفاده می کند. ( i53a4b ) -
lifecycle-process
اکنون به AndroidX Startup 1.1.1 بستگی دارد که یک رگرسیون را در آن ثابت کرد که در آن با استفاده ازProcessLifecycleInitializer
باعث ایجاد یکStartupException
می شود. ( b/216490724 )
نسخه 2.4.0
27 اکتبر 2021
androidx.lifecycle:lifecycle-*:2.4.0
منتشر می شود. نسخه 2.4.0 حاوی این commit ها است.
تغییرات مهم از 2.3.0
-
@OnLifecycleEvent
مستهلک شد. به جای آن باید ازLifecycleEventObserver
یاDefaultLifecycleObserver
استفاده شود. -
androidx.lifecycle:lifecycle-viewmodel-compose
کتابخانه اضافه شد. اینviewModel()
Composable وLocalViewModelStoreOwner
را فراهم می کند.- تغییر منبع :
ViewModelProvider
در کوتلین بازنویسی شده است.ViewModelProvider.Factory.create
Method دیگر اجازه نمی دهد که Generic قابل تهی باشد.
- تغییر منبع :
- API جدید Coroutines به
androidx.lifecycle:lifecycle-runtime-ktx
: -
Lifecycle.repeatOnLifecycle
، API که وقتی چرخه عمر حداقل در یک حالت خاص قرار دارد ، یک کد کد را در یک Coroutine اجرا می کند. با حرکت چرخه عمر در داخل و خارج از حالت هدف ، این بلوک لغو و دوباره راه اندازی می شود. -
Flow.flowWithLifecycle
، API که مقادیر جریان بالادست را هنگام استفاده از چرخه عمر حداقل در یک حالت خاص منتشر می کند. -
DefaultLifecycleObserver
ازlifecycle.lifecycle-common-java8
بهlifecycle.lifecycle-common
.lifecycle.lifecycle-common-java8
هیچ گونه عملکرد دیگری را در بالایlifecycle.lifecycle-common
lifecycle.lifecycle-common
نمی دهد. - API غیر Coroutines از
lifecycle-viewmodel-ktx
به ماژولlifecycle-viewmodel
منتقل شده است. lifecycle-process
در حال حاضر ازandroidx.startup
برای اولیه سازیProcessLifecycleOwner
استفاده می کند.پیش از این ، این کار توسط
androidx.lifecycle.ProcessLifecycleOwnerInitializer
انجام می شد.اگر از
tools:node="remove"
ContentProvider
که برای اولیه سازی چرخه حیات فرآیند در گذشته استفاده می شود ، به جای آن باید موارد زیر را انجام دهید.<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>
نسخه 2.4.0-rc01
29 سپتامبر 2021
androidx.lifecycle:lifecycle-*:2.4.0-rc01
بدون تغییر در چرخه حیات 2.4.0-beta01 منتشر می شود. نسخه 2.4.0-rc01 حاوی این commit ها است.
نسخه 2.4.0-beta01
15 سپتامبر 2021
androidx.lifecycle:lifecycle-*:2.4.0-beta01
منتشر می شود. نسخه 2.4.0-beta01 حاوی این تعهدات است.
تغییرات API
-
@OnLifecycleEvent
مستهلک شد. به جای آن باید ازLifecycleEventObserver
یاDefaultLifecycleObserver
استفاده شود. ( i5a8fa ) - DefaultLifecycleObserver از
androidx.lifecycle.lifecycle-common-java8
بهandroidx.lifecycle.lifecycle-common
منتقل شد.androidx.lifecycle.lifecycle-common-java8
دیگر عملکرد دیگری را در بالایandroidx.lifecycle.lifecycle-common
ارائه نمی دهد ، بنابراین وابستگی به آن را می توان باandroidx.lifecycle.lifecycle-common
جایگزین کرد. ( i021aa ) - API غیر Coroutines از
lifecycle-viewmodel-ktx
به ماژولlifecycle-viewmodel
منتقل شده است. ( i6d5b2 )
مشارکت خارجی
نسخه 2.4.0-alpha03
4 آگوست 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha03
منتشر می شود. نسخه 2.4.0-alpha03 حاوی این commit ها است.
تغییرات API
- تغییر منبع : ViewModelProvider در کوتلین بازنویسی شده است.
ViewModelProvider.Factory.create
Method دیگر اجازه نمی دهد که Generic قابل تهی باشد. ( i9b9f6 )
تغییرات رفتار
-
Lifecycle.repeatOnLifecycle
:block
اکنون همیشه هنگام تکرار اجرای ، به صورت سریال فراخوانی می شود. ( IBAB33 )
مشارکت خارجی
- با تشکر از Chao2zhang برای رفع قطعه های کد در مستندات
repeatOnLifecycle
. شماره 205
نسخه 2.4.0-alpha02
16 ژوئن 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha02
منتشر می شود. نسخه 2.4.0-alpha02 حاوی این commit ها است.
ویژگی های جدید
- یک بررسی جدید
RepeatOnLifecycleWrongUsage
بهlifecycle-runtime-ktx
اضافه کرد که تشخیص می دهد وقتیrepeateOnLifecycle
به طور نادرست درonStart()
یاonResume()
استفاده می شود. ( 706078 ، b/187887400 )
تغییرات API
- API
LifecycleOwner.addRepeatingJob
به نفعLifecycle.repeatOnLifecycle
حذف می شود. Repeatonlifecycle که به همزمانی ساختاری احترام می گذارد و استدلال در مورد آن آسان تر است. ( i4a3a8 ) -
ProcessLifecycleInitializer
عمومی کنید تا سایرandroidx.startup.Initializer
S بتوانند از اینها به عنوان وابستگی استفاده کنند. ( I94C31 )
رفع اشکال
- مسئله ای را با بررسی LINT
NullSafeMutableLiveData
در هنگام اصلاح قسمت ، رفع کرد. ( #147 ، b/183696616 ) - مسئله دیگری را با بررسی Lint
NullSafeMutableLiveData
در هنگام استفاده از Generics برطرف کرد. ( #161 ، b/184830263 )
مشارکت خارجی
- با تشکر از MaxSav برای بهبود بررسی LINT
NullSafeMutableLiveData
. ( #147 ، b/183696616 ) - با تشکر از Kozaxinan برای بهبود بررسی LINT
NullSafeMutableLiveData
. ( #161 ، b/184830263 )
نسخه 2.4.0-alpha01
24 مارس 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha01
منتشر می شود. نسخه 2.4.0-alpha01 حاوی این commit ها است.
تغییرات رفتار
lifecycle-process
در حال حاضر ازandroidx.startup
برای اولیه سازیProcessLifecycleOwner
استفاده می کند.پیش از این ، این کار توسط
androidx.lifecycle.ProcessLifecycleOwnerInitializer
انجام می شد.اگر از
tools:node="remove"
ContentProvider
که برای اولیه سازی چرخه حیات فرآیند در گذشته استفاده می شود ، به جای آن باید موارد زیر را انجام دهید.<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
- یک API
Flow.flowWithLifecycle
اضافه شده است که مقادیر از جریان بالادست را منتشر می کند وقتی که چرخه حیات حداقل در یک حالت خاص با استفاده ازLifecycle.repeatOnLifecycle
باشد. API Repeatonlifecycle. این یک گزینه جایگزین برای API جدیدLifecycleOwner.addRepeatinJob
است. ( i0f4cd )
رفع اشکال
- از چرخه عمر 2.3.1 : قانون Lint
NonNullableMutableLiveData
اکنون می تواند به درستی بین متغیرهای میدانی با قابلیت تهی متفاوت متفاوت باشد. ( b/169249668 )
ViewModel ViewModel نسخه 1.0.0
نسخه 1.0.0-alpha07
16 ژوئن 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07
منتشر می شود. نسخه 1.0.0-alpha07 حاوی این commit ها است.
شکستن API تغییر می کند
-
viewModel()
اکنون یکViewModelStoreOwner
اختیاری می گیرد و کار با صاحبان غیر ازLocalViewModelStoreOwner
را آسان تر می کند. به عنوان مثال ، اکنون می توانید ازviewModel(navBackStackEntry)
برای بازیابی یک ViewModel مرتبط با یک نمودار ناوبری خاص استفاده کنید. ( i2628d ، b/188693123 )
نسخه 1.0.0-alpha06
2 ژوئن 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha06
منتشر می شود. نسخه 1.0.0-alpha06 حاوی این commit ها است.
به روز شده تا با آهنگسازی نسخه 1.0.0-beta08
سازگار باشد.
نسخه 1.0.0-alpha05
18 مه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05
منتشر می شود. نسخه 1.0.0-alpha05 حاوی این commit ها است.
ویژگی های جدید
- به روز شده برای سازگار با نسخه نسخه
1.0.0-beta07
.
رفع اشکال
- پرونده های AndroidManifest از UI-Test-Manifest و Ui-Tooling-Data اکنون با Android 12 سازگار است ( I6F9DE ، B/184718994 )
نسخه 1.0.0-alpha04
7 آوریل 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04
منتشر می شود. نسخه 1.0.0-alpha04 حاوی این commit ها است.
تغییر وابستگی
- این نسخه به
androidx.hilt:hilt-navigation-compose
وandroidx.navigation:navigation-compose
با همگام سازی وابستگی بهandroidx.compose.compiler:compiler:1.0.0-beta04
وandroidx.compose.runtime:runtime:1.0.0-beta04
. برای 1.0.0 ، لازم است که کامپایلر و زمان اجرا مطابقت داشته باشد.
نسخه 1.0.0-alpha03
10 مارس 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03
منتشر می شود. نسخه 1.0.0-alpha03 حاوی این commit ها است.
تغییرات API
-
LocalViewModelStoreOwner.current
اکنون یکViewModelStoreOwner
قابل تهی را برمی گرداند تا بهتر تعیین کند که آیا یکViewModelStoreOwner
در ترکیب فعلی موجود است یا خیر. API هایی که بهViewModelStoreOwner
نیاز دارند ، مانندviewModel()
وNavHost
، اگر یکViewModelStoreOwner
تنظیم نشده باشد ، هنوز یک استثنا را پرتاب می کنند. ( IDF39a )
نسخه حیات-ViewModel-Compose نسخه 1.0.0-alpha02
24 فوریه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02
منتشر می شود. نسخه 1.0.0-alpha02 حاوی این commit ها است.
تغییرات API
-
LocalViewModelStoreOwner
در حال حاضر دارای توابعprovides
است که می تواند باCompositionLocalProvider
استفاده شود و APIasProvidableCompositionLocal()
جایگزین می کند. ( i45d24 )
نسخه حیات-ViewModel-Compose نسخه 1.0.0-alpha01
10 فوریه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01
منتشر می شود. نسخه 1.0.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
-
viewModel()
Composable وLocalViewModelStoreOwner
ازandroidx.compose.ui.viewinterop
به این مصنوعی در بستهandroidx.lifecycle.viewmodel.compose
منتقل شدند. ( i7a374 )
نسخه 2.3.1
نسخه چرخه عمر 2.3.1
24 مارس 2021
androidx.lifecycle:lifecycle-*:2.3.1
منتشر می شود. نسخه 2.3.1 حاوی این commit ها است.
رفع اشکال
- قانون LINT
NonNullableMutableLiveData
اکنون می تواند به درستی بین متغیرهای میدانی با باطل بودن متفاوت تفاوت قائل شود. ( b/169249668 )
نسخه 2.3.0
نسخه 2.3.0
10 فوریه 2021
androidx.lifecycle:lifecycle-*:2.3.0
منتشر می شود. نسخه 2.3.0 حاوی این commit ها است.
تغییرات اساسی از 2.2.0
- پشتیبانی
SavedStateHandle
برای کلاسهای غیر قابل قبول :SavedStateHandle
اکنون با اجازه دادن بهsetSavedStateProvider()
برای یک کلید خاص ، از سریال سازی تنبل پشتیبانی می کند ، ارائه یکSavedStateProvider
که در صورت درخواست ازSavedStateHandle
برای نجات وضعیت خود ، یک تماس تلفنی را برایsaveState()
دریافت می کند. به صرفه جویی در کلاسهای غیر parcelable مراجعه کنید. - اجرای رفتار چرخه عمر :
- زندگی در حال حاضر به عنوان یک کشور ترمینال نابود
DESTROYED
است. -
LifecycleRegistry
اکنون تأیید می کند که روش های آن در موضوع اصلی خوانده می شود. این همیشه الزامی برای حیات فعالیت ها ، قطعات و غیره بود. علاوه بر این از ناظران از موضوعات غیر اصلی منجر به تصادف در زمان اجرا شد. برای اشیاءLifecycleRegistry
که متعلق به مؤلفه های شخصی شما هستند ، می توانید صریحاً با استفاده ازLifecycleRegistry.createUnsafe(...)
از چک ها خودداری کنید ، اما پس از آن باید اطمینان حاصل کنید که هماهنگ سازی مناسب در صورت دسترسی اینLifecycleRegistry
از موضوعات مختلف وجود دارد.
- زندگی در حال حاضر به عنوان یک کشور ترمینال نابود
- یاران حالت چرخه عمر : روشهای یاور استاتیک اضافه شده از
downFrom(State)
،Event
downTo(State)
State
upFrom(State)
،upTo(State)
بهLifecycle.Event
. روشgetTargetState()
را اضافه کرد که به اینState
ارائه می دهد که چرخه عمر به طور مستقیم به دنبال اینEvent
منتقل می شود. -
withStateAtLeast
: API هایLifecycle.withStateAtLeast
که در انتظار حالت چرخه عمر هستند و یک بلوک غیر تعلیق کد را همزمان در نقطه تغییر حالت اجرا می کنند ، سپس با نتیجه از سر می گیرند. این API ها با روش های موجود درwhen*
عدم امکان اجرای کد تعلیق و استفاده از توزیع کننده سفارشی متفاوت هستند. ( AOSP/1326081 ) -
ViewTree
APIS : یکViewTreeLifecycleOwner.get(View)
وViewTreeViewModelStoreOwner.get(View)
API به شما امکان می دهد به ترتیب با توجه به نمونه ایView
، دارایLifecycleOwner
حاوی وViewModelStoreOwner
را بازیابی کنید. شما باید به فعالیت1.2.0
و قطعه1.3.0
و APPCOMPAT 1.3.0-alpha01 یا بالاتر ارتقا دهید تا این موضوع را به درستی جمع کنید. پسوندهایfindViewTreeLifecycleOwner
وfindViewTreeViewModelStoreOwner
Kotlin به ترتیب درlifecycle-runtime-ktx
وlifecycle-viewmodel-ktx
در دسترس هستند. -
LiveData.observe()
استهلاک Kotlin : TheLiveData.observe()
پسوند Kotlin لازم برای استفاده از نحو Lambda اکنون کاهش می یابد زیرا هنگام استفاده از Kotlin 1.4 لازم نیست.
نسخه 2.3.0-rc01
16 دسامبر 2020
androidx.lifecycle:lifecycle-*:2.3.0-rc01
منتشر می شود. نسخه 2.3.0-rc01 حاوی این commit ها است.
رفع اشکال
- روش
keys()
SavedStateHandle
اکنون قبل و بعد از نجات دولت سازگار است - اکنون شامل کلیدهایی است که قبلاً باsetSavedStateProvider()
علاوه بر کلیدهای استفاده شده باset()
وgetLiveData()
استفاده می شود. ( AOSP/1517919 ، b/174713653 )
مشارکت خارجی
- API برای تعلیق Coroutines آگاه از چرخه عمر اکنون بهتر است که تماس های خود را برای
yield()
انجام دهید. با تشکر از نیکلاس Ansman Giertz! ( AOSP/1430830 ، b/168777346 )
نسخه 2.3.0-beta01
1 اکتبر 2020
androidx.lifecycle:lifecycle-*:2.3.0-beta01
منتشر می شود. نسخه 2.3.0-beta01 حاوی این تعهدات است.
تغییرات API
- پسوند Kotlin
LiveData.observe()
لازم برای استفاده از نحو Lambda اکنون کاهش یافته است زیرا هنگام استفاده از Kotlin 1.4 لازم نیست. ( i40d3f )
رفع اشکال
- Androidx را برای استفاده از Kotlin 1.4 ارتقا دهید ( ID6471 ، B/165307851 ، B/165300826 )
تغییرات اسناد و مدارک
- اسناد
liveData
Builder وasLiveData()
به روز شده اند تا جزئیات مربوط به تغییر مقادیر زمان بندی داده شده را شامل شود. ( AOSP/1122324 )
نسخه 2.3.0-alpha07
19 آگوست 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha07
منتشر می شود. نسخه 2.3.0-alpha07 شامل این تعهدات است.
رفع اشکال
- رفع مشکل تصادف در بررسی LINT
NullSafeMutableLiveData
. ( AOSP/1395367 )
نسخه 2.3.0-alpha06
22 جولای 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha06
منتشر می شود. نسخه 2.3.0-alpha06 شامل این تعهدات است.
ویژگی های جدید
- روشهای یاور استاتیک اضافه شده از
downFrom(State)
،downTo(State)
،upFrom(State)
،upTo(State)
بهLifecycle.Event
برای تولید اینEvent
با توجه به یکState
و جهت انتقال. روشgetTargetState()
را اضافه کرد که به اینState
ارائه می دهد که چرخه عمر به طور مستقیم به دنبال اینEvent
منتقل می شود. ( i00887 ) - API های
Lifecycle.withStateAtLeast
اضافه شده که در انتظار حالت چرخه عمر هستند و یک بلوک غیر تعلیق کد را همزمان در نقطه تغییر حالت اجرا می کنند ، سپس با نتیجه از سر می گیرند. این API ها با روش های موجود درwhen*
عدم امکان اجرای کد تعلیق و استفاده از توزیع کننده سفارشی متفاوت هستند. ( AOSP/1326081 )
تغییرات رفتار
- زندگی در حال حاضر به عنوان یک کشور ترمینال نابود
DESTROYED
است. ( i00887 ) -
LifecycleRegistry
اکنون تأیید می کند که روش های آن در موضوع اصلی خوانده می شود. این همیشه الزامی برای حیات فعالیت ها ، قطعات و غیره بود. علاوه بر این از ناظران از موضوعات غیر اصلی منجر به تصادف در زمان اجرا شد. برای اشیاءLifecycleRegistry
که متعلق به مؤلفه های شخصی شما هستند ، می توانید صریحاً با استفاده ازLifecycleRegistry.createUnsafe(...)
از چک ها خودداری کنید ، اما پس از آن شما باید اطمینان حاصل کنید که یک هماهنگLifecycleRegistry
مناسب از این طریق از موضوعات مختلف دسترسی پیدا می کند ( یعنی 7280 ، B/13737392809 )
رفع اشکال
- تصادف در
NullSafeMutableLiveData
را برطرف کرد. ( b/159987480 ) - یک
ObsoleteLintCustomCheck
برای چک های خط بسته بندی شده باlifecycle-livedata-core-ktx
(و به طور خاصNullSafeMutableLiveData
) برطرف کرد. ( b/158699265 )
نسخه 2.3.0-alpha05
24 ژوئن 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha05
منتشر می شود. نسخه 2.3.0-alpha05 حاوی این commit ها است.
رفع اشکال
-
LiveData
اکنون بهتر است موارد retentrant را کنترل کند و از تماس های تکراری بهonActive()
یاonInactive()
جلوگیری کند. ( b/157840298 ) - مشکلی را برطرف کرد که در هنگام استفاده از Android Studio 4.1 Canary 6 یا بالاتر ، چک های LINT اجرا نمی شود. ( AOSP/1331903 )
نسخه 2.3.0-alpha04
10 ژوئن 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha04
منتشر می شود. نسخه 2.3.0-alpha04 حاوی این commit ها است.
رفع اشکال
- تصادف را در بررسی
NonNullableMutableLiveData
بررسی کرد. ( b/157294666 ) - بررسی LINT
NonNullableMutableLiveData
، موارد قابل توجهی بیشتر را در بر می گیرد که مقدارnull
در یکMutableLiveData
با یک پارامتر از نوع غیر تهی تنظیم شده است. ( b/156002218 )
نسخه 2.3.0-alpha03
20 مه 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha03
منتشر می شود. نسخه 2.3.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
-
SavedStateHandle
اکنون با اجازه دادن بهsetSavedStateProvider()
برای یک کلید معین ، از سریال سازی تنبل پشتیبانی می کند ، و یکSavedStateProvider
فراهم می کند که هنگام تماسSavedStateHandle
saveState()
خواسته می شود تا وضعیت خود را نجات دهد. ( b/155106862 ) - API جدید
ViewTreeViewModelStoreOwner.get(View)
به شما امکان می دهد با توجه به نمونهView
ViewModelStoreOwner
را بازیابی کنید. You must upgrade to Activity1.2.0-alpha05
, Fragment1.3.0-alpha05
, and AppCompat1.3.0-alpha01
to populate this correctly. AfindViewModelStoreOwner()
Kotlin extension has been added tolifecycle-viewmodel-ktx
. ( aosp/1295522 )
رفع اشکال
- Fixed an issue that caused the
MutableLiveData
Lint checks released in Lifecycle2.3.0-alpha01
from being published alongside thelifecycle-livedata-core-ktx
artifact. ( b/155323109 )
نسخه 2.3.0-alpha02
29 آوریل 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha02
is released. نسخه 2.3.0-alpha02 حاوی این commit ها است.
تغییرات API
-
SavedStateViewModelFactory
now allows you to pass a nullApplication
to its constructor to better support cases where one is not readily available and support forAndroidViewModel
is not needed. ( aosp/1285740 )
رفع اشکال
- Improved cold start performance by avoiding class verification failure on API 28 and lower devices. ( aosp/1282118 )
نسخه 2.3.0-alpha01
March 4, 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha01
is released. نسخه 2.3.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
- A new
ViewTreeLifecycleOwner.get(View)
API allows you to retrieve the containingLifecycleOwner
given aView
instance. You must upgrade to Activity1.2.0-alpha01
and Fragment1.3.0-alpha01
to populate this correctly. AfindViewTreeLifecycleOwner
Kotlin extension is available inlifecycle-runtime-ktx
. ( aosp/1182361 , aosp/1182956 ) - Added a new Lint check that warns you when setting a
null
value on aMutableLiveData
that has been defined in Kotlin as non-null. This is available when using thelivedata-core-ktx
orlivedata-ktx
artifacts. ( aosp/1154723 , aosp/1159092 ) - A new
lifecycle-runtime-testing
artifact is available that provides aTestLifecycleOwner
that implementsLifecycleOwner
and provides a thread safe mutableLifecycle
. ( aosp/1242438 )
رفع اشکال
- The
lifecycle-runtime
artifact now has a unique package name. ( aosp/1187196 )
نسخه 2.2.0
ViewModel-Savedstate Version 2.2.0
5 فوریه 2020
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0
is released. نسخه 2.2.0 شامل این commit ها است .
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
.
نسخه 2.2.0
22 ژانویه 2020
androidx.lifecycle:lifecycle-*:2.2.0
is released. نسخه 2.2.0 شامل این commit ها است .
تغییرات مهم از 2.1.0
- Lifecycle Coroutine Integration : The new
lifecycle-runtime-ktx
artifact adds integration between Lifecycle and Kotlin coroutines. Thelifecycle-livedata-ktx
has 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 aFragment
orFragmentActivity
to the newViewModelProvider(ViewModelStoreOwner)
constructor to achieve the same functionality when using Fragment1.2.0
. -
lifecycle-extensions
Artifact Deprecation : With the above deprecation ofViewModelProviders.of()
, this release marks the deprecation of the last API inlifecycle-extensions
and this artifact should now be considered deprecated in its entirety. We strongly recommend depending on the specific Lifecycle artifacts you need (such aslifecycle-service
if you're usingLifecycleService
andlifecycle-process
if you're usingProcessLifecycleOwner
) rather thanlifecycle-extensions
as there will not be a future2.3.0
release 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
DefautLifecycleObserver
instead; and if it's written in the Java 7 programming language you can useLifecycleEventObserver
.
Version 2.2.0-rc03
4 دسامبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-rc03
is released. Version 2.2.0-rc03 contains these commits .
رفع اشکال
- Fixed a failure occurring when a mocked
ViewModel
was stored inViewModelStore
and queried later with default factory. - Fix a usage of
Dispatchers.Main.immediate
inlaunchWhenCreated
and 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
7 نوامبر 2019
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 )
نسخه 2.2.0-rc01
23 اکتبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-rc01
is released. Version 2.2.0-rc01 contains these commits .
رفع اشکال
- Fixed an issue where
launchWhenCreated
and related methods would run one frame later than the associated lifecycle method due to its use ofDispatchers.Main
instead ofDispatchers.Main.immediate
. ( aosp/1145596 )
کمک های خارجی
- Thanks to Nicklas Ansman for contributing the fix! ( aosp/1145596 )
نسخه 2.2.0-beta01
9 اکتبر 2019
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
ProcessLifecycleOwner
and the activity'sLifecycleOwner
moving to started and resumed on Android 10 devices. ( aosp/1128132 ) - Fixed a regression introduced in Lifecycle
2.2.0-alpha05
which would cause aNullPointerException
when using version2.0.0
or2.1.0
oflifecycle-process
. ( b/141536990 )
Version 2.2.0-alpha05
18 سپتامبر 2019
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
5 سپتامبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-alpha04
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
-
lifecycleScope
,whenCreated
,whenStarted
,whenResumed
,viewModelScope
, and the underlying implementation ofliveData
now useDispatchers.Main.immediate
instead ofDispatchers.Main
. ( b/139740492 )
کمک های خارجی
- Thanks to Nicklas Ansman for contributing the move to
Dispatchers.Main.immediate
! ( aosp/1106073 )
Version 2.2.0-alpha03
7 آگوست 2019
androidx.lifecycle:lifecycle-*:2.2.0-alpha03
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Implementations of
ViewModelStoreOwner
can now optionally implementHasDefaultViewModelProviderFactory
to 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 تغییر می کند
-
ViewModelProviders.of()
has been deprecated. You can pass aFragment
orFragmentActivity
to the newViewModelProvider(ViewModelStoreOwner)
constructor to achieve the same functionality. ( aosp/1009889 )
نسخه 2.2.0-alpha02
2 جولای 2019
androidx.lifecycle:*:2.2.0-alpha02
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
- Replaced
LiveDataScope.initialValue
withLiveDataScope.latestValue
which will track the current emitted value of theliveData
block. - Added a new overload to the
liveData
builder that receivestimeout
parameter as typeDuration
نسخه 2.2.0-alpha01
7 مه 2019
androidx.lifecycle:*:2.2.0-alpha01
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- 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
نسخه 1.0.0
22 ژانویه 2020
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0
is released. نسخه 1.0.0 حاوی این تعهدات است .
Important features in 1.0.0
- New SavedStateHandle class was added. It enables your
ViewModel
classes to access and to contribute to the saved state. This object can be received in constructor ofViewModel
class and factories provided by default by Fragments and AppCompatActivity will injectSavedStateHandle
automatically. - AbstractSavedStateViewModelFactory was added. It allows you to create custom factories for your
ViewModel
and provide them access toSavedStateHandle
.
ViewModel-Savedstate Version 1.0.0-rc03
4 دسامبر 2019
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
7 نوامبر 2019
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
23 اکتبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc01
is released with no changes from 1.0.0-beta01
. نسخه 1.0.0-rc01 حاوی این commit ها است .
ViewModel-Savedstate Version 1.0.0-beta01
9 اکتبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01
is released. نسخه 1.0.0-beta01 حاوی این تعهدات است .
رفع اشکال
- Fixed an issue where accessing a SavedState ViewModel for the first time in
Activity.onActivityResult()
would result in anIllegalStateException
. ( b/139093676 ) - Fixed an
IllegalStateException
when usingAbstractSavedStateViewModelFactory
. ( b/141225984 )
ViewModel-SavedState Version 1.0.0-alpha05
18 سپتامبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha05
is released. Version 1.0.0-alpha05 contains these commits .
API تغییر می کند
-
SavedStateViewModelFactory
no longer extendsAbstractSavedStateViewModelFactory
andSavedStateHandle
is created only for ViewModels that requested have it ( aosp/1113593 )
ViewModel-SavedState Version 1.0.0-alpha03
7 آگوست 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
شکستن تغییرات
-
lifecycle-viewmodel-savedstate
no longer depends onfragment
and the relatedSavedStateViewModelFactory(Fragment)
andSavedStateViewModelFactory(FragmentActivity)
constructors have been removed. Instead,SavedStateViewModelFactory
is 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
2 جولای 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha02
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Added
SavedStateHandle.getLiveData()
overload which accepts a default value.
تغییرات API
-
SavedStateVMFactory
is renamed toSavedStateViewModelFactory
. -
AbstractSavedStateVMFactory
is renamed toAbstractSavedStateViewModelFactory
.
ViewModel-Savedstate Version 1.0.0-alpha01
13 مارس 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01
is released. The full commit log for this initial release can be found here .
ویژگی های جدید
- Now
ViewModels
can contribute to savedstate. To do that you use newly introduced viewmodel's factorySavedStateVMFactory
and your ViewModel should have a constructor that receivesSavedStateHandle
object as a parameter.
نسخه 2.1.0
تغییرات مهم از 2.0.0
- Added
LifecycleEventObserver
for the cases when a stream of lifecycle events is needed. It is a public API instead of a hiddenGenericLifecycleObserver
class. - Added ktx extensions for
LiveData.observe
methods andTransformations.*
methods. - Added
Transformations.distinctUntilChanged
, which creates a new LiveData object that does not emit a value until the sourceLiveData
value has been changed. - Added coroutine support in ViewModels by adding the extension property
ViewModel.viewModelScope
.
نسخه 2.1.0
5 سپتامبر 2019
androidx.lifecycle:lifecycle-*:2.1.0
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
نسخه 2.1.0-rc01
2 جولای 2019
androidx.lifecycle:*:2.1.0-rc01
is released with no changes from androidx.lifecycle:*:2.1.0-beta01
. commit های موجود در این نسخه را می توانید در اینجا بیابید.
نسخه 2.1.0-beta01
7 مه 2019
androidx.lifecycle:*:2.1.0-beta01
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Lifecycles are graduated to beta: api introduced in previous alphas such as
liveData
extension functions for transformations and observations,ViewModel
initialisation with property delegation and others are stabilised and not going to change.
نسخه 2.1.0-alpha04
3 آوریل 2019
androidx.lifecycle:*:2.1.0-alpha04
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
- Breaking change: the underlying API behind
by viewModels()
andby activityViewModels()
has been changed to support aViewModelStore
directly, rather than only aViewModelStoreOwner
. ( aosp/932932 )
نسخه 2.1.0-alpha03
13 مارس 2019
androidx.lifecycle:*:2.1.0-alpha03
is released. لیست کامل commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
-
ViewModelProvider.KeyedFactory
was removed. Second interface in addition toViewModelProvider.Factory
didn't compose well with new features as property delegation in Kotlinby viewmodels {}
. ( aosp/914133 )
نسخه 2.1.0-alpha02
30 ژانویه 2019
androidx.lifecycle 2.1.0-alpha02
is released.
API تغییر می کند
-
LifecycleRegistry
now contains asetCurrentState()
method that replaces the now deprecatedsetState()
method. ( aosp/880715 )
رفع اشکال
- Fixed an issue where mock
ViewModel
instances would crash when the containingViewModelStore
was cleared. b/122273087
نسخه 2.1.0-alpha01
17 دسامبر 2018
androidx.lifecycle 2.1.0-alpha01
is released.
ویژگی های جدید
- Added
LifecycleEventObserver
for the cases when a stream of lifecycle events is needed. It is a public api instead of a hiddenGenericLifecycleObserver
class. - Added ktx extensions for
LiveData.observe
methods andTransformations.*
methods. - Method
Transformations.distinctUntilChanged
was added. It creates a newLiveData
object that does not emit a value until the source LiveData value has been changed. - Coroutine support in ViewModels: extension property
ViewModel.viewModelScope
was added. - Added
ViewModelProvider.KeyedFactory
, a factory for ViewModels that receiveskey
andClass
increate
method.
نسخه 2.0.0
نسخه 2.0.0
21 سپتامبر 2018
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
نسخه 2.0.0-beta01
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"
}
نسخه 1.1.1
21 مارس 2018
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.
نسخه 1.1.0
22 ژانویه 2018
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
LifecycleActivity
andLifecycleFragment
have now been removed - please useFragmentActivity
,AppCompatActivity
or supportFragment
. -
@NonNull
annotations have been added toViewModelProviders
andViewModelStores
-
ViewModelProviders
constructor has been deprecated - please use its static methods directly -
ViewModelProviders.DefaultFactory
has been deprecated - please useViewModelProvider.AndroidViewModelFactory
- The static
ViewModelProvider.AndroidViewModelFactory.getInstance(Application)
method has been added to retrieve a staticFactory
suitable for creatingViewModel
andAndroidViewModel
instances.
چرخه زندگی
This table lists all the artifacts in the androidx.lifecycle
group.
مصنوع | انتشار پایدار | کاندید را آزاد کنید | نسخه بتا | انتشار آلفا |
---|---|---|---|---|
lifecycle-* | 2.8.7 | - | - | 2.9.0-alpha10 |
lifecycle-viewmodel-compose | 2.8.7 | - | - | 2.9.0-alpha10 |
اعلام وابستگی ها
To add a dependency on Lifecycle, you must add the Google Maven repository to your project. برای اطلاعات بیشتر، مخزن Maven Google را بخوانید.
وابستگیهای مصنوعات مورد نیاز خود را در فایل build.gradle
برای برنامه یا ماژول خود اضافه کنید:
کاتلین
شیار
dependencies { def lifecycle_version = "2.8.7" 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" // 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.8.7" 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") // 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.8.7" 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.8.7" 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 کمک می کند. اگر مسائل جدیدی کشف کردید یا ایده هایی برای بهبود این کتابخانه دارید، به ما اطلاع دهید. لطفاً قبل از ایجاد کتابخانه جدید، به مسائل موجود در این کتابخانه نگاهی بیندازید. با کلیک کردن روی دکمه ستاره می توانید رای خود را به یک موضوع موجود اضافه کنید.
برای اطلاعات بیشتر به مستندات ردیاب مشکل مراجعه کنید.
نسخه 2.9
Version 2.9.0-alpha10
12 فوریه 2025
androidx.lifecycle:lifecycle-*:2.9.0-alpha10
is released. Version 2.9.0-alpha10 contains these commits .
تغییرات API
- Move
MutableStateSerializer
tosavedstate-compose
fromlifecycle-viewmodel-compose
. ( I4f690 , b/378895074 )
مشارکت خارجی
- Adds a new Lint issue for calling
Lifecycle::currentState
in composition, instead suggesting usingcurrentStateAsalue().value
to ensure that changes in the Lifecycle state correctly cause recomposition. Thanks Steven Schoen! ( Iad484 )
Version 2.9.0-alpha09
29 ژانویه 2025
androidx.lifecycle:lifecycle-*:2.9.0-alpha09
is released. Version 2.9.0-alpha09 contains these commits .
ویژگی های جدید
- Add
MutableStateSerializer
for serializingandroidx.compose.runtime.MutableState
. ( Idfc48 , b/378895074 )
تغییرات API
- Replace overloaded
SavedStateHandle.saved()
delegate functions with default parameters ( Icd1c1 ) -
AbstractSavedStateViewModelFactory
is deprecated as it creates aSavedStateHandle
for everyViewModel
, causing unnecessary overhead. UseViewModelProvider.Factory
withCreationExtras.createSavedStateHandle
instead for more efficientViewModel
creation. ( Ia920b , b/388590327 )
Version 2.9.0-alpha08
11 دسامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha08
is released. Version 2.9.0-alpha08 contains these commits .
ویژگی های جدید
- Add
ViewModelScenario.recreate
to simulate a System Process Death recreating theViewModel
under test and all associated components. ( Id6a69 , b/381063087 ) -
LifecycleOwner
andViewModelStoreOwner
instances retrieved via their respectivefindViewTree
APIs can now be resolved through disjoint parents of a view, such as aViewOverlay
. See the release notes of core or the documentation inViewTree.setViewTreeDisjointParent
for more information on disjoint view parents. ( I800f4 )
تغییرات API
- Make the namings and package organization more consistent with
SavedStateRegistryOwnerDelegate
( I8c135 , b/376026744 )
رفع اشکال
- این کتابخانه اکنون از حاشیهنویسیهای پوچ JSpecify استفاده میکند که نوع استفاده هستند. Kotlin developers should use the following compiler arguments to enforce correct usage:
-Xjspecify-annotations=strict, -Xtype-enhancement-improvements-strict-mode
( Ie4340 , b/326456246 ) - Document
ViewModel.onCleared
clearing sequence. ( I586c7 , b/363984116 )
Version 2.9.0-alpha07
13 نوامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha07
is released. Version 2.9.0-alpha07 contains these commits .
Kotlin Multiplatform Compatibility
- Lifecycle
ViewModel SavedState
is now KMP compatible. This allows you to useSavedStateHandle
in 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@Serializable
classes in aSavedStateHandle
and have those classes automatically be restored across process death and recreation. Please note thesaved
delegate is lazy and will not call theinit
lambda or save anything into theSavedStateHandle
until 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
getMutableStateFlow
toSavedStateHandle
to 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
30 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha06
is released. Version 2.9.0-alpha06 contains these commits .
تغییرات رفتار
- The
Lifecycle.DESTROYED
state is terminal, and any attempt to move aLifecycle
from it to any other state will now result in anIllegalStateException
. ( I116c4 , b/370577987 ) -
SavedStateHandle
no longer includes anySavedStateProvider.saveState()
where the returnedBundle
is empty. ( I910b5 , b/370577987 )
رفع اشکال
-
Lifecycle.eventFlow
now correctly complete whenLifecycle
isDESTROYED
( I293b2 , b/374043130 )
Version 2.9.0-alpha05
16 اکتبر 2024
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
2 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha04
is released. Version 2.9.0-alpha04 contains these commits .
چند پلتفرم کاتلین
- The
lifecycle-viewmodel-savedstate
module is now configured to be KMP compatible in preparation for APIs likeSavedStateHandle
being made available in the common source set in a future release. ( I503ed , I48764 , b/334076622 )
Version 2.9.0-alpha03
18 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha03
is released. Version 2.9.0-alpha03 contains these commits .
رفع اشکال
- From Lifecycle
2.8.6
: TheNullSafeMutableLiveData
Lint 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
4 سپتامبر 2024
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.ReportFragment
ProGuard rules to allow obfuscation . ( ff898e1 )
مشارکت خارجی
- Move
androidx.compose.ui.platform.LocalLifecycleOwner
to 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
7 آگوست 2024
androidx.lifecycle:lifecycle-*:2.9.0-alpha01
is released. Version 2.9.0-alpha01 contains these commits .
چند پلتفرم کاتلین
-
lifecycle-testing
is now KMP compatible. ( Iea41e ) - Add support for
linuxArm64
kotlin multiplatform target ( I139d3 , b/338268719 )
ویژگی های جدید
- A new
androidx.lifecycle:lifecycle-viewmodel-testing
KMP artifact is available that provides aViewModelScenario
class for testing ViewModels in isolation, with support foronCleared
(all platforms) andSavedStateHandle
(Android only). ( 337f68d , c9b3409 , 9799a95c , b/264602919 ) - Creating a
ViewModel
withViewModelProvider
is now thread safe;@MainThread
annotations have been removed. ( Ifd978 , b/237006831 )
تغییرات API
- Add the
CreationExtras.Key()
factory function to simplify the creation of anonymousCreationExtras.Key
objects. ( I970ee ) -
CreationExtras
now includes map-like operator overloads to enable idiomatic manipulation of content in Kotlin. It allows the use ofin
,+=
, and+
withCreationExtras
. ( Ib4353 ) -
CreationExtras
now implementsequals
,hashCode
, andtoString
methods. ( Ib4353 ) -
NewInstanceFactory
is now available on JVM Desktop and Android targets. ( d3d0892 ) - Inline extension property to expose underlying Application safely in Kotlin language version 2.0 ( I39df2 )
رفع اشکال
- طرح دستی دسترسی به APIهای پلتفرم جدید حذف شد زیرا این به طور خودکار از طریق مدلسازی API هنگام استفاده از R8 با AGP 7.3 یا جدیدتر (مثلا R8 نسخه 3.3) و برای همه ساختها هنگام استفاده از AGP 8.1 یا بالاتر (به عنوان مثال D8 نسخه 8.1) اتفاق میافتد. به مشتریانی که از AGP استفاده نمیکنند، توصیه میشود به نسخه 8.1 یا بالاتر D8 بهروزرسانی کنند. برای جزئیات بیشتر به این مقاله مراجعه کنید. ( If6b4c , b/345472586 )
نسخه 2.8
Version 2.8.7
30 اکتبر 2024
androidx.lifecycle:lifecycle-*:2.8.7
is released. Version 2.8.7 contains these commits .
تغییرات API
-
androidx.compose.ui.platform.LocalLifecycleOwner
is now available in the common source set (KMP). ( 6a3f5b3 ) -
lifecycle-runtime-compose
:desktop
artifacts were removed and-jvmStubs
and-linuxx64Stubs
artifacts were added. هیچ یک از این اهداف قرار نیست مورد استفاده قرار گیرند، آنها مکان هایی هستند که به تلاش های Jetbrains Compose کمک می کنند. ( 6a3f5b3 )
نسخه 2.8.6
18 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.8.6
is released. Version 2.8.6 contains these commits .
رفع اشکال
- The
NullSafeMutableLiveData
Lint error has improved support for smart casts, avoiding false positives. ( 85fed6 , b/181042665 )
به روز رسانی های وابستگی
- Lifecycle Runtime Compose now depends on Compose Runtime
1.7.1
Version 2.8.5
4 سپتامبر 2024
androidx.lifecycle:lifecycle-*:2.8.5
is released. Version 2.8.5 contains these commits .
رفع اشکال
- Update the
androidx.lifecycle.ReportFragment
ProGuard rules to allow obfuscation . ( ff898e1 )
مشارکت خارجی
-
SavedStateHandle.saveable
extension delegate now supports nullable values. Thanks Roman Kalukiewicz for the contribution. ( 0d78ea6 )
نسخه 2.8.4
24 جولای 2024
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*Effect
completion is now idempotent (ie, if theonStopOrDispose
was called because of the Lifecycle being stopped, it won't be called a second time upon disposal unless the Lifecycle goes back up toSTARTED
again). ( I5f607 , b/352364595 )
نسخه 2.8.3
1 ژوئیه 2024
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 )
نسخه 2.8.2
12 ژوئن 2024
androidx.lifecycle:lifecycle-*:2.8.2
is released. Version 2.8.2 contains these commits .
رفع اشکال
- Fixed
CompositionLocal LocalLifecycleOwner not present
errors 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 ) -
ViewModelProvider
will no longer crash when mixing previous versions ofcompileOnly
Lifecycle dependencies with versions 2.8+, fixing issues with libraries such as LeakCanary. ( I80383 , b/341792251 )
نسخه 2.8.1
29 مه 2024
androidx.lifecycle:lifecycle-*:2.8.1
is released. Version 2.8.1 contains these commits .
رفع اشکال
-
lifecycle-viewmodel-compose
now only has a common dependency oncompose-runtime
, removing its common dependency oncompose-ui
. The Android artifact retains itscompose-ui
for compatibility. ( aosp/3079334 , b/339562627 ) -
ViewModel
'ssaveable
integration 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 )
نسخه 2.8.0
14 مه 2024
androidx.lifecycle:lifecycle-*:2.8.0
is released. Version 2.8.0 contains these commits .
Important changes since 2.7.0
-
LocalLifecycleOwner
has been moved from Compose UI tolifecycle-runtime-compose
so that its Compose-based helper APIs can be used outside of Compose UI. - The
lifecycle-runtime-compose
artifact now contains thedropUnlessResumed
anddropUnlessStarted
APIs which allow you to drop click or other events that occur even after theLifecycleOwner
has 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.viewModelScope
is now an overridable constructor parameter, allowing you to inject your own dispatcher andSupervisorJob()
or to override the default by using thebackgroundScope
available 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) }
ViewModel
has been rewritten in Kotlin and now usesAutoClosable
instead ofCloseable
. It now supports addingAutoCloseable
objects with akey
that allows retrieving them viagetCloseable()
.Calling
LifecycleStartEffect
andLifecycleResumeEffect
without a key is now an error, following the same convention as theDisposableEffect
API that these APIs mirror.Deprecated
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)
in favor ofLiveData.toPublisher(lifecycleOwner)
.The
lifecycle-livedata-core-ktx
kotlin extensions have now been moved to thelifecycle-livedata-core
module.The
NullSafeMutableLiveData
has 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-common
moves most APIs tocommon
and supports jvm and iOS in addition to Android. -
lifecycle-runtime
moves most APIs tocommon
and supports jvm and iOS in addition to Android. -
lifecycle-runtime-ktx
is now empty, with all APIs being moved intolifecycle-runtime
. -
lifecycle-runtime-compose
moves all APIs tocommon
and 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
ViewModelProvider
instance is now done through theViewModelProvider.create()
methods rather than directly calling its constructor. -
ViewModelProvider.NewInstanceFactory
andViewModelProvider.AndroidViewModelFactory
are only available on Android.- Custom Factories are recommended to extend from
ViewModelProvider.Factory
and use thecreate
method that takes aCreationExtras
or use theviewModelFactory
Kotlin DSL.
- Custom Factories are recommended to extend from
- Using
ViewModelProvider
without 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. -
viewModelScope
will fallback to anEmptyCoroutineContext
in platforms whereDispatchers.Main
is not available (eg, Linux).
Artifacts impacted:
-
lifecycle-viewmodel
moves most APIs tocommon
and supports jvm and iOS in addition to Android. -
lifecycle-viewmodel-ktx
is now empty, with all APIs being moved intolifecycle-viewmodel
. -
lifecycle-viewmodel-compose
moves all APIs tocommon
and ships an Android artifact, matching the multiplatform support ofandroidx.compose
.
تغییرات رفتار
-
InitializerViewModelFactory
(includingviewModelFactory
builder function) will now throw anIllegalArgumentException
if ainitializer
with the sameclazz: KClass<VM : ViewModel>
has already been added. ( Ic3a36 )
مسائل شناخته شده
-
lifecycle-*:2.8.0
requires a minimum Compose version of 1.7.0-alpha05 ( b/336842920 ).
Version 2.8.0-rc01
1 مه 2024
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-common
classes was not properly packaged. These are now packaged in thelifecycle-runtime
AAR. ( aosp/3038274 , b/322382422 ) - Fixed an unintentional ordering change in how
AutoCloseable
instances 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
viewModelScope
for native and JVM Desktop environments. ( aosp/3039221 )
مشارکت خارجی
- Thanks Victor Kropp for improving the checking for the main thread on JVM Desktop. ( aosp/3037116 )
Version 2.8.0-beta01
17 آوریل 2024
androidx.lifecycle:lifecycle-*:2.8.0-beta01
is released. Version 2.8.0-beta01 contains these commits .
ویژگی های جدید
- The
lifecycle-runtime-compose
artifact is now compatible with Kotlin Multiplatform, moving its code tocommon
and ships an Android artifact, matching the multiplatform support forandroidx.compose
. ( If7a71 , I4f4a0 , b/331769623 )
Version 2.8.0-alpha04
3 آوریل 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha04
is released. Version 2.8.0-alpha04 contains these commits .
ویژگی های جدید
- The
lifecycle-viewmodel-compose
artifact is now compatible with Kotlin Multiplatform, moving its code tocommon
and ships an Android artifact, matching the multiplatform support ofandroidx.compose
. The accommodate this change, the ComposableviewModel
method now accepts aKClass
in addition to ajava.lang.Class
. ( b/330323282 )
رفع اشکال
- The
NullSafeMutableLiveData
has been refactored to avoid many false positives. ( I2d8c1 , Iafb18 , I03463 , I7ecef )
Dependency update
- The
lifecycle-viewmodel-compose
artifact now depends on Compose 1.6.0. - Lifecycle now depends on Profile Installer 1.3.1 .
Version 2.8.0-alpha03
20 مارس 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha03
is released. Version 2.8.0-alpha03 contains these commits .
ویژگی های جدید
ViewModel.viewModelScope
is now an overridable constructor parameter, allowing you to inject your own dispatcher andSupervisorJob()
or to override the default by using thebackgroundScope
available 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
ViewModelProvider
instance is now done through theViewModelProvider.create()
methods rather than directly calling its constructor. -
ViewModelProvider.NewInstanceFactory
andViewModelProvider.AndroidViewModelFactory
are only available on Android.- Custom Factories are recommended to extend from
ViewModelProvider.Factory
and use thecreate
method that takes aCreationExtras
or use theviewModelFactory
Kotlin DSL.
- Custom Factories are recommended to extend from
- Using
ViewModelProvider
without 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. -
viewModelScope
will fallback to anEmptyCoroutineContext
in platforms whereDispatchers.Main
is not available (eg, Linux).
تغییرات رفتار
-
InitializerViewModelFactory
(includingviewModelFactory
builder function) will now throw anIllegalArgumentException
if ainitializer
with the sameclazz: KClass<VM : ViewModel>
has already been added. ( Ic3a36 )
رفع اشکال
-
ViewModel.getCloseable
now handles duplicated keys: if thekey
already has anAutoCloseable
resource associated with it, the old resource will be replaced and closed immediately. ( Ibeb67 ) - Accessing the
viewModelScope
of aViewModel
is now thread safe. ( If4766 , b/322407038 )
مشارکت خارجی
-
LocalLifecycleOwner
از Compose UI به lifecycle-runtime-compose منتقل شد تا API های کمکی مبتنی بر Compose آن بتوانند خارج از Compose UI استفاده شوند. با تشکر از جیک وارتون برای کمک. ( I6c41b , b/328263448 )
Version 2.8.0-alpha02
21 فوریه 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha02
is released. Version 2.8.0-alpha02 contains these commits.
ویژگی های جدید
- The
dropUnlessResumed
anddropUnlessStarted
APIs have been added which allow you to drop click or other events that occur even after theLifecycleOwner
has 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 )
Kotlin Conversions
-
ViewModel
is now written in Kotlin ( I16f26 , b/214568825 ) - The
lifecycle-viewmodel-ktx
kotlin extensions have now been moved to the base lifecycle module. ( Id787b , b/274800183 ) - The
lifecycle-runtime-ktx
kotlin extensions have now been moved to the base lifecycle module. ( Ic3686 , b/274800183 ) - The
lifecycle-livedata-core-ktx
kotlin 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
, andLifecycleRegistry
are now shipped in artifacts compatible with Kotlin Multiplatform. ( b/317249252 )
تغییرات API
- Calling
LifecycleStartEffect
andLifecycleResumeEffect
without a key is now an error, following the same convention as theDisposableEffect
API that these APIs mirror. ( Ib0e0c , b/323518079 ) -
ViewModel
now usesAutoCloseable
instead ofCloseable
. That is a backward compatible change. ( I27f8e , b/214568825 ) - Deprecated
LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)
in favor ofLiveData.toPublisher(lifecycleOwner)
. ( Iabe29 , b/262623005 )
مشارکت خارجی
- Thanks Ivan Matkov from Jetbrains for helping move Lifecycle to Kotlin Multiplatform. ( aosp/2926690 , I0c5ac , If445d )
Version 2.8.0-alpha01
24 ژانویه 2024
androidx.lifecycle:lifecycle-*:2.8.0-alpha01
is released. Version 2.8.0-alpha01 contains these commits.
ویژگی های جدید
-
ViewModel
now supports addingCloseable
objects with akey
that allows retrieving them viagetCloseable()
. ( I3cf63 )
نسخه 2.7
نسخه 2.7.0
10 ژانویه 2024
androidx.lifecycle:lifecycle-*:2.7.0
is released. Version 2.7.0 contains these commits.
Important changes since 2.6.0
-
TestLifecycleOwner
now includes a suspending functionsetCurrentState()
which ensures that the state change and allLifecycleObserver
callbacks are completed before returning. Notably, unlike setting thecurrentState
property directly, this does not userunBlocking
, making it safe to use within a coroutine such as one provided byrunTest
. - The
LiveData
extensions ofmap
andswitchMap
now mirror the behavior ofdistinctUntilChanged
- if theLiveData
has avalue
set, themap
/switchMap
function will be immediately called to populate thevalue
of 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 sourceLiveData
will still only apply once you start observing theLiveData
. - This release fixes an issue where
SavedStateHandle
would not properly restore customParcelable
classes 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
, andgetStateFlow
now specifically calls this limitation out. - The proguard keep rules associated with
LifecycleObserver
have been removed. This means that proguarded code that wishes to use APIs via reflection (such as using the long since deprecated@OnLifecycleEvent
annotation) 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 aFlow
ofLifecycle.Event
via theLifecycle.asFlow()
extension method. - Jetpack Compose users can now use
LifecycleEventEffect
to 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
LifecycleStartEffect
andLifecycleResumeEffect
to handle pairs of events - started to stopped and resumed to paused, respectively. This API mirrors the one found inDisposableEffect
and 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.State
can now be observed via theLifecycle.currentStateFlow
property, which returns aStateFlow
where thevalue
is the currentLifecycle.State
. - Jetpack Compose users can use the
Lifecycle.currentStateAsState()
extension to directly exposeLifecycle.State
as 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
13 دسامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-rc02
is released. Version 2.7.0-rc02 contains these commits.
رفع اشکال
- Fixed an issue where
SavedStateHandle
would not properly restore customParcelable
classes 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
, andgetStateFlow
now specifically calls this limitation out. ( I0b55a )
Version 2.7.0-rc01
15 نوامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-rc01
is released. Version 2.7.0-rc01 contains these commits.
رفع اشکال
-
LifecycleStartEffect
andLifecycleResumeEffect
now correctly dispose and recreate the effect block if theLifecycleOwner
is changed. ( Ia25c6 )
نسخه 2.7.0-beta01
1 نوامبر 2023
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.
نسخه 2.7.0-alpha03
18 اکتبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha03
is released. Version 2.7.0-alpha03 contains these commits.
ویژگی های جدید
-
lifecycle-runtime-testing
now contains a new Lint check to avoid setting theLifecycle.State
of theTestLifecycleOwner
by using thecurrentState
field when inside of a coroutine. The Lint check now suggests the suspendingsetCurrentState
which allows setting theLifecycle.State
without blocking. ( Icf728 , b/297880630 )
رفع اشکال
- Fixed an issue with
LiveData.switchMap
where returning the sameLiveData
instance both on the initial call and a subsequent call would prevent theLiveData
instance from being added as a source. ( Ibedcba7 )
نسخه 2.7.0-alpha02
6 سپتامبر 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha02
is released. Version 2.7.0-alpha02 contains these commits.
ویژگی های جدید
-
TestLifecycleOwner
now includes the suspending functionsetCurrentState()
to give users the option of usingTestLifecycleOwner
from within a coroutine such as one provided byrunTest
. ( I329de , b/259344129 )
تغییرات API
- All files from the
lifecycle-livedata-ktx
modules have been moved into the mainlifecycle-livedata
module. ( I10c6f , b/274800183 )
تغییرات رفتار
- The
LiveData.map()
andLiveData.switchMap()
extensions now sets thevalue
of the returnedLiveData
if the previousLiveData
has 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 theCloseable
if theViewModel
has already received a call toonCleared()
. ( I4712e , b/280294730 )
رفع اشکال
- From Lifecycle
2.6.2
: Fixed an issue whereSavedStateHandle
would 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 betweenrememberSaveable
and Navigation Compose'sNavHost
. ( aosp/2729289 )
نسخه 2.7.0-alpha01
26 جولای 2023
androidx.lifecycle:lifecycle-*:2.7.0-alpha01
is released. Version 2.7.0-alpha01 contains these commits.
تغییرات API
-
Lifecycle.State
is now Compose-observable viaLifecycle.currentStateFlow
, which returns aStateFlow
where thevalue
is the currentLifecycle.State
. ( Ib212d , b/209684871 ) -
Lifecycle.Event
s can now able to be observed as aFlow
withLifecycle.asFlow().
( If2c0f , b/176311030 ) -
LifecycleResumeEffect
API has been added to run ComposeSideEffect
s based on bothLifecycle.Event.ON_RESUME
andLifecycle.Event.ON_PAUSE
event callbacks. ( I60386 , b/235529345 ) -
LifecycleStartEffect
API has been added to run ComposeSideEffect
s based onLifecycle.Event.ON_START
andLifecycle.Event.ON_STOP
event callbacks. ( I5a8d1 , b/235529345 ) -
LifecycleEventEffect
API has been added to run ComposeSideEffect
s based onLifecycle.Event
. ( Ic9794 , b/235529345 ) -
Lifecycle.collectAsState()
extension has been added to directly exposeLifecycle.State
as ComposeState
. This is equivalent (and a shorter alternative) tolifecycle.currentStateFlow.collectAsState()
. ( I11015 , b/235529345 )
رفع اشکال
- The
LiveData.distinctUntilChanged()
extension now sets thevalue
of the returnedLiveData
if the previousLiveData
has had a value set on it. This does not change the observation behavior - updated values from the sourceLiveData
will still only apply once you start observing theLiveData
returned fromdistinctUntilChanged()
. ( Ib482f ) - The proguard keep rules associated with
LifecycleObserver
have 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 )
نسخه 2.6
نسخه 2.6.2
6 سپتامبر 2023
androidx.lifecycle:lifecycle-*:2.6.2
is released. Version 2.6.2 contains these commits.
رفع اشکال
- Fixed an issue where
SavedStateHandle
would 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 betweenrememberSaveable
and Navigation Compose'sNavHost
. ( aosp/2729289 )
نسخه 2.6.1
22 مارس 2023
androidx.lifecycle:lifecycle-*:2.6.1
is released. نسخه 2.6.1 حاوی این commit ها است.
به روز رسانی های وابستگی
-
lifecycle-viewmodel-savedstate
now depends on SavedState1.2.1
. ( cd7251 ) - Lifecycle now depends on ProfileInstaller
1.3.0
. ( f9d30b )
نسخه 2.6.0
8 مارس 2023
androidx.lifecycle:lifecycle-*:2.6.0
is released. نسخه 2.6.0 حاوی این commit ها است.
تغییرات مهم از 2.5.0
-
LiveData
now includes a newisInitialized
property that indicates whether an explicit value has ever been set on theLiveData
, allowing you to distinguish betweenliveData.value
returningnull
because no value has ever been set or an explicitnull
value. -
MediatorLiveData
now includes a constructor to set an initial value. - Added a new extension on
StateFlow
andFlow
ofcollectAsStateWithLifecycle()
that collect from flows and represents its latest value as Compose State in a lifecycle-aware manner. -
Lifecycle.launchWhenX
methods andLifecycle.whenX
methods 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
onChanged
method of aObserver
created in Kotlin now matches the nullability of the generic type. If you wantObserver.onChanged()
to accept a nullable type, you must instantiate theObserver
with 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
نسخه 2.6.0-rc01
22 فوریه 2023
androidx.lifecycle:lifecycle-*:2.6.0-rc01
is released. نسخه 2.6.0-rc01 حاوی این commit ها است.
رفع اشکال
- The
LiveData.distinctUntilChanged()
extension now sets thevalue
of the returnedLiveData
if the previousLiveData
has had a value set on it. This does not change the observation behavior - updated values from the sourceLiveData
will still only apply once you start observing theLiveData
returned fromdistinctUntilChanged()
. ( Ib482f )
نسخه 2.6.0-beta01
8 فوریه 2023
androidx.lifecycle:lifecycle-*:2.6.0-beta01
is released. نسخه 2.6.0-beta01 حاوی این تعهدات است.
Kotlin Conversions
-
LifecycleOwner
is now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thelifecycle
property rather than implementing the previousgetLifecycle()
function. ( I75b4b , b/240298691 ) -
ViewModelStoreOwner
is now in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override theviewModelStore
property rather than implementing the previousgetViewModelStore()
function. ( I86409 , b/240298691 ) - The Kotlin extension on
LifecycleOwner
that provides thelifecycleScope
field has been moved to thelifecycle-common
artifact fromlifecycle-runtime-ktx
. ( I41d78 , b/240298691 ) - The Kotlin extension on
Lifecycle
that provides thecoroutineScope
field has been moved to thelifecycle-common
artifact fromlifecycle-runtime-ktx
. ( Iabb91 , b/240298691 )
Version 2.6.0-alpha05
25 ژانویه 2023
androidx.lifecycle:lifecycle-*:2.6.0-alpha05
is released. Version 2.6.0-alpha05 contains these commits.
Kotlin Conversions
-
Transformations
is 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.Function
method are deprecated and replaced with the versions that take a KotlinFunction1
. This change maintains binary compatibility. ( I8e14f ) -
ViewTreeViewModelStoreOwner
is 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 onView
ofandroidx.lifecycle.setViewTreeViewModelStoreOwner
andandroidx.lifecycle.findViewTreeViewModelStoreOwner
to 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
HasDefaultViewModelProviderFactory
interface is now written in Kotlin. This is a source incompatible change for classes written in Kotlin - they must now override thedefaultViewModelProviderFactory
anddefaultViewModelCreationExtras
properties rather than implementing the previous corresponding functions. ( Iaed9c , b/240298691 ) -
Observer
is now written in Kotlin. ItsonChanged()
method now uses the namevalue
for its parameter. ( Iffef2 , I4995e , b/240298691 ) -
AndroidViewModel
,AbstractSavedStateViewModelFactory
,LifecycleService
,ServiceLifecycleDispatcher
, andProcessLifecycleOwner
are now written in Kotlin ( I2e771 , Ibae40 , I160d7 , I08884 , I1cda7 , b/240298691 )
Version 2.6.0-alpha04
11 ژانویه 2023
androidx.lifecycle:lifecycle-*:2.6.0-alpha04
is released. Version 2.6.0-alpha04 contains these commits.
ویژگی های جدید
-
LiveData
now includes a newisInitialized
property that indicates whether an explicit value has ever been set on theLiveData
, allowing you to distinguish betweenliveData.value
returningnull
because no value has ever been set or an explicitnull
value. ( Ibd018 )
تغییرات API
- The
collectAsStateWithLifecycle()
APIs oflifecycle-runtime-compose
are no longer in experimental status. ( I09d42 , b/258835424 ) -
Lifecycle.launchWhenX
methods andLifecycle.whenX
methods 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 )
Kotlin Conversions
-
ViewTreeLifecycleOwner
is 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 onView
ofandroidx.lifecycle.setViewTreeLifecycleOwner
andandroidx.lifecycle.findViewTreeLifecycleOwner
to 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 ) -
LiveDataReactiveStreams
is now written in Kotlin. The Kotlin extensions previously inlifecycle-reactivestreams-ktx
have been moved into thelifecycle-reactivestreams
module 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
, andViewModelStore
are now written in Kotlin ( Iadffd , ( I60034 , I8c52c , I9593d , I01fe1 , I59a23 , b/240298691 )
رفع اشکال
-
SavedStateHandle
no longer crashes with aClassCastException
when callingget()
with the incorrect class type. ( I6ae7c )
نسخه 2.6.0-alpha03
24 اکتبر 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha03
is released. نسخه 2.6.0-alpha03 حاوی این commit ها است.
رفع اشکال
- 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 )
نسخه 2.6.0-alpha02
7 سپتامبر 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha02
is released. نسخه 2.6.0-alpha02 حاوی این commit ها است.
تغییرات API
-
MediatorLiveData
now includes a constructor to set an initial value. ( Ib6cc5 , b/151244085 )
رفع اشکال
-
Lifecycle
artifacts 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 acallbackFlow
rather than using its ownChannel
implementation to ensure thread-safety and context preservation. ( I4a8b2 , b/200596935 ) -
FlowLiveData
'sasLiveData
function will now preserve the initial value of aStateFlow
when creating the newLiveData
object. ( I3f530 , b/157380488 ) - From Lifecycle
2.5.1
: Custom implementations ofAndroidViewModelFactory
now correctly calls thecreate(modelClass)
function when using the stateful constructor withLifecycle
2.4+ ( I5b315 , b/238011621 )
نسخه 2.6.0-alpha01
29 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.6.0-alpha01
is released. نسخه 2.6.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
- Added a new extension on
StateFlow
andFlow
ofcollectAsStateWithLifecycle
that 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 )
نسخه 2.5
نسخه 2.5.1
27 جولای 2022
androidx.lifecycle:lifecycle-*:2.5.1
is released. نسخه 2.5.1 حاوی این commit ها است.
رفع اشکال
- Custom implementations of
AndroidViewModelFactory
now correctly call thecreate(modelClass)
function when using the statefulAndroidViewModelFactory
constructor withLifecycle
2.4+. ( I5b315 , b/238011621 )
نسخه 2.5.0
29 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.5.0
is released. نسخه 2.5.0 شامل این commit ها است.
تغییرات مهم از 2.4.0
SavedStateHandle
now offers agetStateFlow()
API that returns a KotlinStateFlow
for monitoring value changes as an alternative to usingLiveData
.ViewModel CreationExtras - when writing a custom
ViewModelProvider.Factory
, it is no longer required to extendAndroidViewModelFactory
orAbstractSavedStateViewModelFactory
to gain access to anApplication
orSavedStateHandle
, respectively. Instead, these fields are provided to everyViewModelProvider.Factory
subclass asCreationExtras
via the new overload ofcreate
:create(Class<T>, CreationExtras)
. These extras are provided automatically by your Activity or Fragment when using Activity1.5.0
and 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-viewmodel
now provides aviewModelFactory
Kotlin DSL that allows you define yourViewModelProvider.Factory
in terms of one or more lambda initializers, one for each particularViewModel
class your custom factory supports, usingCreationExtras
as 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-compose
now offers aviewModel()
API that takes a lambda factory for creating aViewModel
instance 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-compose
artifact now contains new experimental APIs inSavedStateHandle.saveable
that allowrememberSaveable
like behavior backed by theSavedStateHandle
of 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 moreCloseable
objects to theViewModel
that will be closed when theViewModel
is 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
CoroutineScope
that 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
ViewModel
constructor 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 }
تغییر رفتار
- Attempting to move the
Lifecycle.State
fromINITIALIZED
toDESTROYED
will now always throw anIllegalStateException
regardless of whether theLifecycle
has an attached observer. -
LifecycleRegistry
will now clear their observers when they reach theDESTROYED
state.
Version 2.5.0-rc02
15 ژوئن 2022
androidx.lifecycle:lifecycle-*:2.5.0-rc02
is released. Version 2.5.0-rc02 contains these commits.
رفع اشکال
-
ViewModelProvider
will no longer crash when mixing previous versions of compileOnly Lifecycle dependencies with versions 2.5+. ( I81a66 , b/230454566 )
نسخه 2.5.0-rc01
11 مه 2022
androidx.lifecycle:lifecycle-*:2.5.0-rc01
is released. نسخه 2.5.0-rc01 حاوی این commit ها است.
رفع اشکال
-
MediatorLiveData.addSource()
now throws aNullPointerException
when passed anull
source instead of propagating thenull
source to observers.( Ibd0fb , b/123085232 )
نسخه 2.5.0-beta01
20 آوریل 2022
androidx.lifecycle:lifecycle-*:2.5.0-beta01
is released. نسخه 2.5.0-beta01 حاوی این تعهدات است.
تغییرات API
- Added
SavedStateHandle.saveable
property delegates to use property names as keys for persisting state into theSavedStateHandle
( I8bb86 , b/225014345 )
رفع اشکال
- Fixed an issue where nesting one
NavHost
within anotherNavHost
in a non-primary bottom navigation tab would lead to anIllegalStateException
when using multiple back stacks. ( I11bd5 , b/228865698 )
نسخه 2.5.0-alpha06
6 آوریل 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha06
is released. Version 2.5.0-alpha06 contains these commits.
ویژگی های جدید
- Add experimental
MutableState
overload toSavedStateHandle.saveable
for parity withrememberSaveable
( I38cfe , b/224565154 )
تغییرات API
-
CreationExtras
is now abstract instead of sealed. ( Ib8a7a )
رفع اشکال
- Fixed an
IllegalStateException: Already attached to lifecycleOwner
error caused bySavedStateHandleController
. ( I7ea47 , b/215406268 )
نسخه 2.5.0-alpha05
23 مارس 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha05
is released. Version 2.5.0-alpha05 contains these commits.
ویژگی های جدید
- The
lifecycle-viewmodel-compose
module now providesSavedStateHandleSaver
, an experimental API that ensures values in aSavedStateHandle
are integrated correctly with the same saved instance state thatrememberSaveable
uses. ( Ia88b7 , b/195689777 )
تغییرات API
- Fixed a compatibility issue with Lifecycle 2.3 and newer Lifecycle versions in Java. ( I52c8a , b/219545060 )
رفع اشکال
-
SavedStateViewFactory
now supports usingCreationExtras
even when it was initialized with aSavedStateRegistryOwner
. If extras are provided, the initialized arguments are ignored. ( I6c43b , b/224844583 )
نسخه 2.5.0-alpha04
9 مارس 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha04
is released. Version 2.5.0-alpha04 contains these commits.
تغییرات API
-
SavedStateHandle
now offers agetStateFlow()
API that returns a KotlinStateFlow
for monitoring value changes as an alternative to usingLiveData
. ( Iad3ab , b/178037961 )
نسخه 2.5.0-alpha03
23 فوریه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha03
is released. نسخه 2.5.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
- Added an
addCloseable()
API and a new constructor overload that allow you to add one or moreCloseable
objects to theViewModel
that will be closed when theViewModel
is cleared without requiring any manual work inonCleared()
. ( I55ea0 ) -
lifecycle-viewmodel
now provides anInitializerViewModelFactory
that allows you to add lambda for handling particularViewModel
classes, usingCreationExtras
as the primary data source. ( If58fc , b/216687549 ) -
lifecycle-viewmodel-compose
now offers aviewModel()
API that takes a lambda factory for creating aViewModel
instance without requiring the creation of a customViewModelProvider.Factory
. ( I97fbb , b/216688927 )
تغییرات API
- You can now create a
ViewModel
withCreationExtras
vialifecycle-viewmodel-compose
. ( I08887 , b/216688927 )
تغییر رفتار
- Attempting to move the
Lifecycle.State
fromINITIALIZED
toDESTROYED
will now always throw anIllegalStateException
regardless of whether theLifecycle
has an attached observer. ( I7c390 , b/177924329 ) -
LifecycleRegistry
will now clear their observers when they reach theDESTROYED
state. ( I4f8dd , b/142925860 )
نسخه 2.5.0-alpha02
9 فوریه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha02
is released. نسخه 2.5.0-alpha02 حاوی این commit ها است.
تغییرات API
-
SavedStateHandle
andSavedStateViewModelFactory
have been converted to Kotlin. This has improved the nullability of the generics in both classes. ( Ib6ce2 , b/216168263 , I9647a , b/177667711 ) - The
LiveData
switchMap
function parameter can now have a nullable output. ( I40396 , b/132923666 ) - The
LiveData
-ktx extensions are now annotated with@CheckResult
to enforce that the result is used when calling these functions. ( Ia0f05 , b/207325134 )
تغییر رفتار
-
SavedStateHandle
now properly stores the defaultValue when no value for the specified key exists. ( I1c6ce , b/178510877 )
رفع اشکال
- From Lifecycle
2.4.1
: Updatedlifecycle-process
to depend on Startup 1.1.1 to ensure that fixes that preventProcessLifecycleInitializer
from throwing aStartupException
are available by default. ( Ib01df , b/216490724 ) - There is now an improved error message when custom
AndroidViewModel
classes have parameters in the wrong order and attempt to create aViewModel
. ( I340f7 , b/177667711 ) - You can now create a view model via
CreationExtras
using theAndroidViewModelFactory
without setting an application. ( I6ebef , b/217271656 )
نسخه 2.5.0-alpha01
26 ژانویه 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha01
is released. نسخه 2.5.0-alpha01 حاوی این commit ها است.
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
: thisString
provides access to the custom key you passed toViewModelProvider.get()
. -
ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY
provides access to theApplication
class. -
SavedStateHandleSupport.SAVED_STATE_REGISTRY_OWNER_KEY
provides access to theSavedStateRegistryOwner
that is being used to construct this ViewModel. -
SavedStateHandleSupport.VIEW_MODEL_STORE_OWNER_KEY
provides access to theViewModelStoreOwner
that is being used to construct this ViewModel. -
SavedStateHandleSupport.DEFAULT_ARGS_KEY
provides access to theBundle
of 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
SavedStateHandle
would reappear after process death and recreation, even if it was specifically removed from theSavedStateHandle
. As a consequence of this,SavedStateHandle
will no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b )
نسخه 2.4
نسخه 2.4.1
9 فوریه 2022
androidx.lifecycle:lifecycle-*:2.4.1
is released. نسخه 2.4.1 حاوی این commit ها است.
رفع اشکال
- Backported from Lifecycle
2.5.0-alpha01
: Fixed an issue where the default value provided to aSavedStateHandle
would re-appear after process death and recreation, even if it was specifically removed from theSavedStateHandle
. As a consequence of this,SavedStateHandle
will no longer merge default values and restored values together, instead only using the restored values as the source of truth. ( I53a4b ) -
lifecycle-process
now depends on Androidx Startup 1.1.1 which fixed a regression in where usingProcessLifecycleInitializer
would cause anStartupException
. ( b/216490724 )
نسخه 2.4.0
27 اکتبر 2021
androidx.lifecycle:lifecycle-*:2.4.0
is released. نسخه 2.4.0 حاوی این commit ها است.
تغییرات مهم از 2.3.0
-
@OnLifecycleEvent
was deprecated.LifecycleEventObserver
orDefaultLifecycleObserver
should be used instead. -
androidx.lifecycle:lifecycle-viewmodel-compose
library was added. It providesviewModel()
composable andLocalViewModelStoreOwner
.- Source-breaking change :
ViewModelProvider
has been rewritten in Kotlin.ViewModelProvider.Factory.create
method 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. -
DefaultLifecycleObserver
was moved fromlifecycle.lifecycle-common-java8
tolifecycle.lifecycle-common
.lifecycle.lifecycle-common-java8
doesn'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-ktx
have been moved to thelifecycle-viewmodel
module. lifecycle-process
now usesandroidx.startup
to initialize theProcessLifecycleOwner
.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer
.If you used
tools:node="remove"
theContentProvider
being 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>
نسخه 2.4.0-rc01
29 سپتامبر 2021
androidx.lifecycle:lifecycle-*:2.4.0-rc01
is released with no changes from Lifecycle 2.4.0-beta01. نسخه 2.4.0-rc01 حاوی این commit ها است.
نسخه 2.4.0-beta01
15 سپتامبر 2021
androidx.lifecycle:lifecycle-*:2.4.0-beta01
is released. نسخه 2.4.0-beta01 حاوی این تعهدات است.
تغییرات API
-
@OnLifecycleEvent
was deprecated.LifecycleEventObserver
orDefaultLifecycleObserver
should be used instead. ( I5a8fa ) - DefaultLifecycleObserver was moved from
androidx.lifecycle.lifecycle-common-java8
toandroidx.lifecycle.lifecycle-common
.androidx.lifecycle.lifecycle-common-java8
doesn'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-ktx
have been moved to thelifecycle-viewmodel
module. ( I6d5b2 )
مشارکت خارجی
نسخه 2.4.0-alpha03
4 آگوست 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha03
is released. نسخه 2.4.0-alpha03 حاوی این commit ها است.
تغییرات API
- Source-breaking change : ViewModelProvider has been rewritten in Kotlin.
ViewModelProvider.Factory.create
method no longer allows nullable generic. ( I9b9f6 )
تغییرات رفتار
- The
Lifecycle.repeatOnLifecycle
:block
is now always invoked serially when repeating execution. ( Ibab33 )
مشارکت خارجی
- Thanks chao2zhang for fixing the code snippets in the
repeatOnLifecycle
documentation. #205 .
نسخه 2.4.0-alpha02
16 ژوئن 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha02
is released. نسخه 2.4.0-alpha02 حاوی این commit ها است.
ویژگی های جدید
- Added a new
RepeatOnLifecycleWrongUsage
lint check tolifecycle-runtime-ktx
that detects whenrepeateOnLifecycle
is incorrectly used inonStart()
oronResume()
. ( 706078 , b/187887400 )
تغییرات API
- The
LifecycleOwner.addRepeatingJob
API is removed in favor ofLifecycle.repeatOnLifecycle
that respects structured concurrency and is easier to reason about. ( I4a3a8 ) - Make
ProcessLifecycleInitializer
public so otherandroidx.startup.Initializer
s can use these as dependencies. ( I94c31 )
رفع اشکال
- Fixed an issue with the
NullSafeMutableLiveData
lint check when the field has modifiers. ( #147 , b/183696616 ) - Fixed another issue with the
NullSafeMutableLiveData
lint check when using generics. ( #161 , b/184830263 )
مشارکت خارجی
- Thanks maxsav for improving the
NullSafeMutableLiveData
lint check. ( #147 , b/183696616 ) - Thanks kozaxinan for improving the
NullSafeMutableLiveData
lint check. ( #161 , b/184830263 )
نسخه 2.4.0-alpha01
24 مارس 2021
androidx.lifecycle:lifecycle-*:2.4.0-alpha01
is released. نسخه 2.4.0-alpha01 حاوی این commit ها است.
تغییرات رفتار
lifecycle-process
now usesandroidx.startup
to initialize theProcessLifecycleOwner
.Previously, this was being done by
androidx.lifecycle.ProcessLifecycleOwnerInitializer
.If you used
tools:node="remove"
theContentProvider
being 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.flowWithLifecycle
API that emits values from the upstream Flow when the lifecycle is at least in a certain state using theLifecycle.repeatOnLifecycle
API. This is an alternative to the also newLifecycleOwner.addRepeatinJob
API. ( I0f4cd )
رفع اشکال
- From Lifecycle 2.3.1 : The
NonNullableMutableLiveData
lint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
Lifecycle Viewmodel Compose Version 1.0.0
نسخه 1.0.0-alpha07
16 ژوئن 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07
is released. نسخه 1.0.0-alpha07 حاوی این commit ها است.
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 )
نسخه 1.0.0-alpha06
2 ژوئن 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha06
is released. نسخه 1.0.0-alpha06 حاوی این commit ها است.
Updated to be compatible with Compose version 1.0.0-beta08
.
نسخه 1.0.0-alpha05
18 مه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05
is released. نسخه 1.0.0-alpha05 حاوی این commit ها است.
ویژگی های جدید
- 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 )
نسخه 1.0.0-alpha04
7 آوریل 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04
is released. نسخه 1.0.0-alpha04 حاوی این commit ها است.
Dependency Changes
- This version allows
androidx.hilt:hilt-navigation-compose
andandroidx.navigation:navigation-compose
to sync dependencies onandroidx.compose.compiler:compiler:1.0.0-beta04
andandroidx.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
10 مارس 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03
is released. نسخه 1.0.0-alpha03 حاوی این commit ها است.
تغییرات API
-
LocalViewModelStoreOwner.current
now returns a nullableViewModelStoreOwner
to better determine whether aViewModelStoreOwner
is available in the current composition. APIs that require aViewModelStoreOwner
, such asviewModel()
andNavHost
, still throw an exception if aViewModelStoreOwner
is not set. ( Idf39a )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha02
24 فوریه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02
is released. نسخه 1.0.0-alpha02 حاوی این commit ها است.
تغییرات API
-
LocalViewModelStoreOwner
now has aprovides
functions that can be used withCompositionLocalProvider
, replacing theasProvidableCompositionLocal()
API. ( I45d24 )
Lifecycle-Viewmodel-Compose Version 1.0.0-alpha01
10 فوریه 2021
androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01
is released. نسخه 1.0.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
- The
viewModel()
composable andLocalViewModelStoreOwner
were moved fromandroidx.compose.ui.viewinterop
to this artifact in theandroidx.lifecycle.viewmodel.compose
package. ( I7a374 )
نسخه 2.3.1
Lifecycle Version 2.3.1
24 مارس 2021
androidx.lifecycle:lifecycle-*:2.3.1
is released. نسخه 2.3.1 حاوی این commit ها است.
رفع اشکال
- The
NonNullableMutableLiveData
lint rule can now properly differentiate between field variables with different nullability. ( b/169249668 )
نسخه 2.3.0
نسخه 2.3.0
10 فوریه 2021
androidx.lifecycle:lifecycle-*:2.3.0
is released. نسخه 2.3.0 حاوی این commit ها است.
Major changes since 2.2.0
-
SavedStateHandle
support for non-parcelable classes :SavedStateHandle
now supports lazy serialization by allowing you to callsetSavedStateProvider()
for a given key, providing aSavedStateProvider
that will get a callback tosaveState()
when theSavedStateHandle
is asked to save its state. See Saving non-parcelable classes . - Lifecycle Behavior Enforcement :
- LifecycleRegistry now enforces
DESTROYED
as a terminal state. -
LifecycleRegistry
now 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. ForLifecycleRegistry
objects 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 thisLifecycleRegistry
is 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.Event
for generating theEvent
given aState
and transition direction. Added thegetTargetState()
method that provides theState
that the Lifecycle will transition to directly following theEvent
. -
withStateAtLeast
: AddedLifecycle.withStateAtLeast
APIs 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 ) -
ViewTree
APIs : A newViewTreeLifecycleOwner.get(View)
andViewTreeViewModelStoreOwner.get(View)
API allows you to retrieve the containingLifecycleOwner
andViewModelStoreOwner
, respectively, given aView
instance. You must upgrade to Activity1.2.0
and Fragment1.3.0
, and AppCompat 1.3.0-alpha01 or higher to populate this correctly. ThefindViewTreeLifecycleOwner
andfindViewTreeViewModelStoreOwner
Kotlin extensions are available inlifecycle-runtime-ktx
andlifecycle-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.
نسخه 2.3.0-rc01
16 دسامبر 2020
androidx.lifecycle:lifecycle-*:2.3.0-rc01
is released. نسخه 2.3.0-rc01 حاوی این commit ها است.
رفع اشکال
- The
keys()
method ofSavedStateHandle
is 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 )
مشارکت خارجی
- The APIs to suspend Lifecycle-aware coroutines now better handle calls to
yield()
. Thanks Nicklas Ansman Giertz! ( aosp/1430830 , b/168777346 )
نسخه 2.3.0-beta01
1 اکتبر 2020
androidx.lifecycle:lifecycle-*:2.3.0-beta01
is released. نسخه 2.3.0-beta01 حاوی این تعهدات است.
تغییرات 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 )
تغییرات اسناد و مدارک
- The
liveData
builder andasLiveData()
docs have been updated to include details about changing the given timeout values. ( aosp/1122324 )
Version 2.3.0-alpha07
19 آگوست 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha07
is released. Version 2.3.0-alpha07 contains these commits.
رفع اشکال
- Fixed a crash issue in the
NullSafeMutableLiveData
Lint check. ( aosp/1395367 )
Version 2.3.0-alpha06
22 جولای 2020
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.Event
for generating theEvent
given aState
and transition direction. Added thegetTargetState()
method that provides theState
that the Lifecycle will transition to directly following theEvent
. ( I00887 ) - Added
Lifecycle.withStateAtLeast
APIs 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
DESTROYED
as a terminal state. ( I00887 ) -
LifecycleRegistry
now 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. ForLifecycleRegistry
objects 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 thisLifecycleRegistry
is accessed from different threads ( Ie7280 , b/137392809 )
رفع اشکال
- Fixed a crash in
NullSafeMutableLiveData
. ( b/159987480 ) - Fixed an
ObsoleteLintCustomCheck
for Lint checks bundled withlifecycle-livedata-core-ktx
(and specificallyNullSafeMutableLiveData
). ( b/158699265 )
نسخه 2.3.0-alpha05
24 ژوئن 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha05
is released. نسخه 2.3.0-alpha05 حاوی این commit ها است.
رفع اشکال
-
LiveData
now 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 )
نسخه 2.3.0-alpha04
10 ژوئن 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha04
is released. نسخه 2.3.0-alpha04 حاوی این commit ها است.
رفع اشکال
- Fixed a crash in the
NonNullableMutableLiveData
Lint check. ( b/157294666 ) - The
NonNullableMutableLiveData
Lint check now covers significantly more cases where anull
value was set on aMutableLiveData
with a non-null type parameter. ( b/156002218 )
نسخه 2.3.0-alpha03
20 مه 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha03
are released. نسخه 2.3.0-alpha03 حاوی این commit ها است.
ویژگی های جدید
-
SavedStateHandle
now supports lazy serialization by allowing you to callsetSavedStateProvider()
for a given key, providing aSavedStateProvider
that will get a callback tosaveState()
when theSavedStateHandle
is asked to save its state. ( b/155106862 ) - A new
ViewTreeViewModelStoreOwner.get(View)
API allows you to retrieve the containingViewModelStoreOwner
given aView
instance. You must upgrade to Activity1.2.0-alpha05
, Fragment1.3.0-alpha05
, and AppCompat1.3.0-alpha01
to populate this correctly. AfindViewModelStoreOwner()
Kotlin extension has been added tolifecycle-viewmodel-ktx
. ( aosp/1295522 )
رفع اشکال
- Fixed an issue that caused the
MutableLiveData
Lint checks released in Lifecycle2.3.0-alpha01
from being published alongside thelifecycle-livedata-core-ktx
artifact. ( b/155323109 )
نسخه 2.3.0-alpha02
29 آوریل 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha02
is released. نسخه 2.3.0-alpha02 حاوی این commit ها است.
تغییرات API
-
SavedStateViewModelFactory
now allows you to pass a nullApplication
to its constructor to better support cases where one is not readily available and support forAndroidViewModel
is not needed. ( aosp/1285740 )
رفع اشکال
- Improved cold start performance by avoiding class verification failure on API 28 and lower devices. ( aosp/1282118 )
نسخه 2.3.0-alpha01
March 4, 2020
androidx.lifecycle:lifecycle-*:2.3.0-alpha01
is released. نسخه 2.3.0-alpha01 حاوی این commit ها است.
ویژگی های جدید
- A new
ViewTreeLifecycleOwner.get(View)
API allows you to retrieve the containingLifecycleOwner
given aView
instance. You must upgrade to Activity1.2.0-alpha01
and Fragment1.3.0-alpha01
to populate this correctly. AfindViewTreeLifecycleOwner
Kotlin extension is available inlifecycle-runtime-ktx
. ( aosp/1182361 , aosp/1182956 ) - Added a new Lint check that warns you when setting a
null
value on aMutableLiveData
that has been defined in Kotlin as non-null. This is available when using thelivedata-core-ktx
orlivedata-ktx
artifacts. ( aosp/1154723 , aosp/1159092 ) - A new
lifecycle-runtime-testing
artifact is available that provides aTestLifecycleOwner
that implementsLifecycleOwner
and provides a thread safe mutableLifecycle
. ( aosp/1242438 )
رفع اشکال
- The
lifecycle-runtime
artifact now has a unique package name. ( aosp/1187196 )
نسخه 2.2.0
ViewModel-Savedstate Version 2.2.0
5 فوریه 2020
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0
is released. نسخه 2.2.0 شامل این commit ها است .
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
.
نسخه 2.2.0
22 ژانویه 2020
androidx.lifecycle:lifecycle-*:2.2.0
is released. نسخه 2.2.0 شامل این commit ها است .
تغییرات مهم از 2.1.0
- Lifecycle Coroutine Integration : The new
lifecycle-runtime-ktx
artifact adds integration between Lifecycle and Kotlin coroutines. Thelifecycle-livedata-ktx
has 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 aFragment
orFragmentActivity
to the newViewModelProvider(ViewModelStoreOwner)
constructor to achieve the same functionality when using Fragment1.2.0
. -
lifecycle-extensions
Artifact Deprecation : With the above deprecation ofViewModelProviders.of()
, this release marks the deprecation of the last API inlifecycle-extensions
and this artifact should now be considered deprecated in its entirety. We strongly recommend depending on the specific Lifecycle artifacts you need (such aslifecycle-service
if you're usingLifecycleService
andlifecycle-process
if you're usingProcessLifecycleOwner
) rather thanlifecycle-extensions
as there will not be a future2.3.0
release 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
DefautLifecycleObserver
instead; and if it's written in the Java 7 programming language you can useLifecycleEventObserver
.
Version 2.2.0-rc03
4 دسامبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-rc03
is released. Version 2.2.0-rc03 contains these commits .
رفع اشکال
- Fixed a failure occurring when a mocked
ViewModel
was stored inViewModelStore
and queried later with default factory. - Fix a usage of
Dispatchers.Main.immediate
inlaunchWhenCreated
and 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
7 نوامبر 2019
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 )
نسخه 2.2.0-rc01
23 اکتبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-rc01
is released. Version 2.2.0-rc01 contains these commits .
رفع اشکال
- Fixed an issue where
launchWhenCreated
and related methods would run one frame later than the associated lifecycle method due to its use ofDispatchers.Main
instead ofDispatchers.Main.immediate
. ( aosp/1145596 )
کمک های خارجی
- Thanks to Nicklas Ansman for contributing the fix! ( aosp/1145596 )
نسخه 2.2.0-beta01
9 اکتبر 2019
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
ProcessLifecycleOwner
and the activity'sLifecycleOwner
moving to started and resumed on Android 10 devices. ( aosp/1128132 ) - Fixed a regression introduced in Lifecycle
2.2.0-alpha05
which would cause aNullPointerException
when using version2.0.0
or2.1.0
oflifecycle-process
. ( b/141536990 )
Version 2.2.0-alpha05
18 سپتامبر 2019
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
5 سپتامبر 2019
androidx.lifecycle:lifecycle-*:2.2.0-alpha04
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
-
lifecycleScope
,whenCreated
,whenStarted
,whenResumed
,viewModelScope
, and the underlying implementation ofliveData
now useDispatchers.Main.immediate
instead ofDispatchers.Main
. ( b/139740492 )
کمک های خارجی
- Thanks to Nicklas Ansman for contributing the move to
Dispatchers.Main.immediate
! ( aosp/1106073 )
Version 2.2.0-alpha03
7 آگوست 2019
androidx.lifecycle:lifecycle-*:2.2.0-alpha03
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Implementations of
ViewModelStoreOwner
can now optionally implementHasDefaultViewModelProviderFactory
to 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 تغییر می کند
-
ViewModelProviders.of()
has been deprecated. You can pass aFragment
orFragmentActivity
to the newViewModelProvider(ViewModelStoreOwner)
constructor to achieve the same functionality. ( aosp/1009889 )
نسخه 2.2.0-alpha02
2 جولای 2019
androidx.lifecycle:*:2.2.0-alpha02
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
- Replaced
LiveDataScope.initialValue
withLiveDataScope.latestValue
which will track the current emitted value of theliveData
block. - Added a new overload to the
liveData
builder that receivestimeout
parameter as typeDuration
نسخه 2.2.0-alpha01
7 مه 2019
androidx.lifecycle:*:2.2.0-alpha01
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- 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
نسخه 1.0.0
22 ژانویه 2020
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0
is released. نسخه 1.0.0 حاوی این تعهدات است .
Important features in 1.0.0
- New SavedStateHandle class was added. It enables your
ViewModel
classes to access and to contribute to the saved state. This object can be received in constructor ofViewModel
class and factories provided by default by Fragments and AppCompatActivity will injectSavedStateHandle
automatically. - AbstractSavedStateViewModelFactory was added. It allows you to create custom factories for your
ViewModel
and provide them access toSavedStateHandle
.
ViewModel-Savedstate Version 1.0.0-rc03
4 دسامبر 2019
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
7 نوامبر 2019
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
23 اکتبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-rc01
is released with no changes from 1.0.0-beta01
. نسخه 1.0.0-rc01 حاوی این commit ها است .
ViewModel-Savedstate Version 1.0.0-beta01
9 اکتبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01
is released. نسخه 1.0.0-beta01 حاوی این تعهدات است .
رفع اشکال
- Fixed an issue where accessing a SavedState ViewModel for the first time in
Activity.onActivityResult()
would result in anIllegalStateException
. ( b/139093676 ) - Fixed an
IllegalStateException
when usingAbstractSavedStateViewModelFactory
. ( b/141225984 )
ViewModel-SavedState Version 1.0.0-alpha05
18 سپتامبر 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha05
is released. Version 1.0.0-alpha05 contains these commits .
API تغییر می کند
-
SavedStateViewModelFactory
no longer extendsAbstractSavedStateViewModelFactory
andSavedStateHandle
is created only for ViewModels that requested have it ( aosp/1113593 )
ViewModel-SavedState Version 1.0.0-alpha03
7 آگوست 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
شکستن تغییرات
-
lifecycle-viewmodel-savedstate
no longer depends onfragment
and the relatedSavedStateViewModelFactory(Fragment)
andSavedStateViewModelFactory(FragmentActivity)
constructors have been removed. Instead,SavedStateViewModelFactory
is 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
2 جولای 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha02
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Added
SavedStateHandle.getLiveData()
overload which accepts a default value.
تغییرات API
-
SavedStateVMFactory
is renamed toSavedStateViewModelFactory
. -
AbstractSavedStateVMFactory
is renamed toAbstractSavedStateViewModelFactory
.
ViewModel-Savedstate Version 1.0.0-alpha01
13 مارس 2019
androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01
is released. The full commit log for this initial release can be found here .
ویژگی های جدید
- Now
ViewModels
can contribute to savedstate. To do that you use newly introduced viewmodel's factorySavedStateVMFactory
and your ViewModel should have a constructor that receivesSavedStateHandle
object as a parameter.
نسخه 2.1.0
تغییرات مهم از 2.0.0
- Added
LifecycleEventObserver
for the cases when a stream of lifecycle events is needed. It is a public API instead of a hiddenGenericLifecycleObserver
class. - Added ktx extensions for
LiveData.observe
methods andTransformations.*
methods. - Added
Transformations.distinctUntilChanged
, which creates a new LiveData object that does not emit a value until the sourceLiveData
value has been changed. - Added coroutine support in ViewModels by adding the extension property
ViewModel.viewModelScope
.
نسخه 2.1.0
5 سپتامبر 2019
androidx.lifecycle:lifecycle-*:2.1.0
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
نسخه 2.1.0-rc01
2 جولای 2019
androidx.lifecycle:*:2.1.0-rc01
is released with no changes from androidx.lifecycle:*:2.1.0-beta01
. commit های موجود در این نسخه را می توانید در اینجا بیابید.
نسخه 2.1.0-beta01
7 مه 2019
androidx.lifecycle:*:2.1.0-beta01
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
ویژگی های جدید
- Lifecycles are graduated to beta: api introduced in previous alphas such as
liveData
extension functions for transformations and observations,ViewModel
initialisation with property delegation and others are stabilised and not going to change.
نسخه 2.1.0-alpha04
3 آوریل 2019
androidx.lifecycle:*:2.1.0-alpha04
is released. commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
- Breaking change: the underlying API behind
by viewModels()
andby activityViewModels()
has been changed to support aViewModelStore
directly, rather than only aViewModelStoreOwner
. ( aosp/932932 )
نسخه 2.1.0-alpha03
13 مارس 2019
androidx.lifecycle:*:2.1.0-alpha03
is released. لیست کامل commit های موجود در این نسخه را می توانید در اینجا بیابید.
API تغییر می کند
-
ViewModelProvider.KeyedFactory
was removed. Second interface in addition toViewModelProvider.Factory
didn't compose well with new features as property delegation in Kotlinby viewmodels {}
. ( aosp/914133 )
نسخه 2.1.0-alpha02
30 ژانویه 2019
androidx.lifecycle 2.1.0-alpha02
is released.
API تغییر می کند
-
LifecycleRegistry
now contains asetCurrentState()
method that replaces the now deprecatedsetState()
method. ( aosp/880715 )
رفع اشکال
- Fixed an issue where mock
ViewModel
instances would crash when the containingViewModelStore
was cleared. b/122273087
نسخه 2.1.0-alpha01
17 دسامبر 2018
androidx.lifecycle 2.1.0-alpha01
is released.
ویژگی های جدید
- Added
LifecycleEventObserver
for the cases when a stream of lifecycle events is needed. It is a public api instead of a hiddenGenericLifecycleObserver
class. - Added ktx extensions for
LiveData.observe
methods andTransformations.*
methods. - Method
Transformations.distinctUntilChanged
was added. It creates a newLiveData
object that does not emit a value until the source LiveData value has been changed. - Coroutine support in ViewModels: extension property
ViewModel.viewModelScope
was added. - Added
ViewModelProvider.KeyedFactory
, a factory for ViewModels that receiveskey
andClass
increate
method.
نسخه 2.0.0
نسخه 2.0.0
21 سپتامبر 2018
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
نسخه 2.0.0-beta01
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"
}
نسخه 1.1.1
21 مارس 2018
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.
نسخه 1.1.0
22 ژانویه 2018
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
LifecycleActivity
andLifecycleFragment
have now been removed - please useFragmentActivity
,AppCompatActivity
or supportFragment
. -
@NonNull
annotations have been added toViewModelProviders
andViewModelStores
-
ViewModelProviders
constructor has been deprecated - please use its static methods directly -
ViewModelProviders.DefaultFactory
has been deprecated - please useViewModelProvider.AndroidViewModelFactory
- The static
ViewModelProvider.AndroidViewModelFactory.getInstance(Application)
method has been added to retrieve a staticFactory
suitable for creatingViewModel
andAndroidViewModel
instances.