(提案)ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する#578
Conversation
|
Your app is deployed! Try it via https://deploygate.com/distributions/eaf4c330bf9539ad4b73fc53edd28a20f693a045 |
Apk comparision results
Generated by 🚫 Danger |
| @@ -3,20 +3,21 @@ package io.github.droidkaigi.confsched2019.announcement.ui.actioncreator | |||
| import androidx.lifecycle.Lifecycle | |||
| @@ -2,21 +2,22 @@ package io.github.droidkaigi.confsched2019.sponsor.ui.actioncreator | |||
|
|
|||
| import androidx.lifecycle.Lifecycle | |||
|
|
||
| import androidx.annotation.IntDef | ||
|
|
||
| class ScreenLifecycle { |
There was a problem hiding this comment.
Is it possible to make ScreenLifecycle a Lifecycle of AAC?
ScreenLifecycleをAACのライフサイクルにすることって可能ですかね?
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| class SponsorActionCreator @Inject constructor( |
There was a problem hiding this comment.
If you do not make a scope here, another SponsorActionCreator will be created when the screen rotates, is it difficult to make the scope?
画面回転時にもう一個インスタンスができてしまうんですが、スコープを付けるのって難しいですかね、、?
There was a problem hiding this comment.
これは難しそうなので、とりあえずなくてもいいかもですね。。
| /** | ||
| * This implementation refers to https://github.com/Kotlin/kotlinx.coroutines/pull/760 | ||
| */ | ||
| fun ScreenLifecycle.createJob( |
There was a problem hiding this comment.
この実装の思想は「画面回転を跨いだActivity」が最長ライフサイクルである前提に立ってると思うんですが、実際には Application が最大であり、それに対応できていないこと、また Supervisor を使ってのViewModelのインスタンススコープから外れた Global な実装は取扱を間違えると memory leak しそうです。正確には、この実装が暗黙的なライフサイクルとコールバックチェーンに支えられていて、コードだけ見ても memory leak しないという自信がないです。
また Dagger の Provide 部分が非同期になると memory cache に適切なsemaphoreがなくて、パッと見 memory leak 無しに動くか怪しいです。非同期で provide することは現状視野に入れてませんが、暗黙的にその制約がつくのはあまり好ましくないというのが正直な感想です。
Twitter でちらっと見た感じの印象としては ViewModel が直接 CoroutineScope (と必要であれば Dagger2 のComponent) を管理するイメージでした。(最新の ktx alpha の方式)
Pros/Cons を見たいんですが、この方式で最新の ktx alpha と比較したときの Pros/Cons ってなんでしょうか?
There was a problem hiding this comment.
ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する
僕個人として、この考え自体には凄い賛成です。特にこのアプリはこの考えの恩恵をかなり受けられそうです。
There was a problem hiding this comment.
これの方式との比較が気になるという感じですかね?確かにAACのライフサイクル化よりそちらを先に考えたほうがいいかもですねー
https://qiita.com/kafumi/items/8a8764679df8646b764a
Issue
Overview (Required)
Links
Screenshot