Status Update
Comments
il...@google.com <il...@google.com>
tr...@gmail.com <tr...@gmail.com> #2
reemission of the same liveData is racy
a....@gmail.com <a....@gmail.com> #3
sj...@gmail.com <sj...@gmail.com> #4
sj...@gmail.com <sj...@gmail.com> #5
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
sa...@google.com <sa...@google.com>
ap...@google.com <ap...@google.com> #6
lm...@gmail.com <lm...@gmail.com> #7
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
lm...@gmail.com <lm...@gmail.com> #8
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
lm...@gmail.com <lm...@gmail.com> #9
ap...@google.com <ap...@google.com> #10
Branch: androidx-main
commit e9afa3a28b32897fef6717fea079c6296f3a2e5a
Author: sanura <sanura@google.com>
Date: Tue Apr 25 01:07:17 2023
Create LifecycleEventEffect composable
Adding LifecycleEventEffect composable API to
be used when running SideEffects based on a
particular Lifecycle.Event.
RelNote: "`LifecycleEventEffect` API has been
added to run side effects based on `Lifecycle.Event`."
Test: LifecycleEventEffectTest
Bug: 235529345
Change-Id: Ic9794d7e59b1a66cc7f31cbaebed9b3d3dee5dd3
M lifecycle/lifecycle-runtime-compose/api/current.txt
M lifecycle/lifecycle-runtime-compose/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-runtime-compose/api/restricted_current.txt
M lifecycle/lifecycle-runtime-compose/src/androidTest/java/androidx/lifecycle/compose/CollectAsStateWithLifecycleTests.kt
A lifecycle/lifecycle-runtime-compose/src/androidTest/java/androidx/lifecycle/compose/LifecycleEffectTest.kt
M lifecycle/lifecycle-runtime-compose/src/androidTest/java/androidx/lifecycle/compose/LifecycleExtTest.kt
A lifecycle/lifecycle-runtime-compose/src/main/java/androidx/lifecycle/compose/LifecycleEffect.kt
ap...@google.com <ap...@google.com> #11
Branch: androidx-main
commit 25a2002ab933ea551295483aa3f7e278d60dbe75
Author: sanura <sanura@google.com>
Date: Wed May 03 20:20:56 2023
Create LifecycleResumeEffect composable
Adding LifecycleResumeEffect composable API to be used when
running SideEffects based on ON_RESUME/ON_PAUSE event callbacks.
RelNote: "`LifecycleResumeEffect` API has been added to run side
effects based on both `Lifecycle.Event.ON_RESUME` and
`Lifecycle.Event.ON_PAUSE` event callbacks."
Test: lifecycleResumeEffectTest
Bug: 235529345
Change-Id: I603860f21eb6a433c909d7ae6f8120f6d23179aa
M lifecycle/lifecycle-runtime-compose/api/current.txt
M lifecycle/lifecycle-runtime-compose/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-runtime-compose/api/restricted_current.txt
M lifecycle/lifecycle-runtime-compose/src/androidTest/java/androidx/lifecycle/compose/LifecycleEffectTest.kt
M lifecycle/lifecycle-runtime-compose/src/main/java/androidx/lifecycle/compose/LifecycleEffect.kt
ap...@google.com <ap...@google.com> #12
Branch: androidx-main
commit 2b090a54b8182927eb0e96062e0a14d065a8561a
Author: sanura <sanura@google.com>
Date: Tue May 02 19:53:55 2023
Create LifecycleStartEffect composable
Adding LifecycleStartEffect composable API to be used when
running SideEffects based on ON_START/ON_STOP event callbacks.
RelNote: "`LifecycleStartEffect` API has been added to run side
effects based on `Lifecycle.Event.ON_START` and
`Lifecycle.Event.ON_STOP` event callbacks."
Test: lifecycleStartEffectTest
Bug: 235529345
Change-Id: I5a8d1e6f152b7083e086146ba97044c4b454db84
M lifecycle/lifecycle-runtime-compose/api/current.txt
M lifecycle/lifecycle-runtime-compose/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-runtime-compose/api/restricted_current.txt
M lifecycle/lifecycle-runtime-compose/src/androidTest/java/androidx/lifecycle/compose/LifecycleEffectTest.kt
M lifecycle/lifecycle-runtime-compose/src/main/java/androidx/lifecycle/compose/LifecycleEffect.kt
st...@gmail.com <st...@gmail.com> #13
Is there a target API version where this may be released?
il...@google.com <il...@google.com> #14
This is still in progress for inclusion in Lifecycle 2.7.0-alpha01.
ap...@google.com <ap...@google.com> #15
Branch: androidx-main
commit ad273fa4882a38a5a2f72004044ce3173b2c06a9
Author: sanura <sanura@google.com>
Date: Fri May 05 02:02:59 2023
Add samples for LifecycleEffects
Adding samples for LifecycleEventEffect,
LifecycleStartEffect, and LifecycleResumeEffect.
RelNote: "All composables in `LifecycleEffect` now
link sample usages."
Test: ./gradlew bOS
Bug: 235529345
Change-Id: Ib4786f4b586cf9390f3dbe6f3b0fc86c60267a86
M lifecycle/lifecycle-runtime-compose/samples/src/main/java/androidx/lifecycle/compose/samples/LifecycleComposeSamples.kt
M lifecycle/lifecycle-runtime-compose/src/main/java/androidx/lifecycle/compose/LifecycleEffect.kt
sa...@google.com <sa...@google.com>
lm...@gmail.com <lm...@gmail.com> #16
ka...@gmail.com <ka...@gmail.com> #17
When will this be released?
na...@google.com <na...@google.com> #18
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.lifecycle:lifecycle-runtime-compose:2.7.0-alpha01
sj...@gmail.com <sj...@gmail.com> #19
Just want to say that Lifecycle 2.7.0
stable has been finally released. Thank you very much 🙏🏼
ey...@gmail.com <ey...@gmail.com> #20
jb...@google.com <jb...@google.com> #21
Yes, those are the Lifecycle.State
s that reflect those particular Lifecycle.Event
s. Please take a look at the
ey...@gmail.com <ey...@gmail.com> #22
jb...@google.com <jb...@google.com> #23
Receiving a state from the flow would be the signal that a change has occurred and the new state is that particular change. There are cases where you don't care how you get to a state, just that you are there. We also offer Lifecycle.Event
s.
il...@google.com <il...@google.com> #24
If you look at the Lifecycle.asFlow()
to get a Flow of Lifecycle.Event
) and one for Lifecycle State (where you can use Lifecycle.currentStateFlow
to get the current Lifecycle.State
).
Make sure you are using the right API.
ey...@gmail.com <ey...@gmail.com> #25
il...@google.com <il...@google.com> #26
Lifecycle.asFlow()
works outside of Compose too and gives you Lifecycle.Event
instances as they occur. That's why that API exists separately from currentStateFlow
.
Description
Component used: Lifecycle
Version used: 2.5.0-rc01
Reacting to a Lifecycle.State changes is currently fairly complicated in a Jetpack Compose based app, requiring a with registering a
DisposableEffect
based approachLifecycleObserver
with theLocalLifecycleOwner
.Ideally, this would come in two forms:
Lifecycle.State
asState
, perhaps something likeLocalLifecycleOwner.current.lifecycle.currentStateFlow.collectAsState()
LifecycleEventEffect
that would only run the effect when theLifecycle.State
changes.