-
Notifications
You must be signed in to change notification settings - Fork 264
(提案)ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
(提案)ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する #578
Conversation
|
Your app is deployed! Try it via https://deploygate.com/distributions/eaf4c330bf9539ad4b73fc53edd28a20f693a045 |
Apk comparision results
Generated by 🚫 Danger |
| @@ -1,22 +1,23 @@ | |||
| package io.github.droidkaigi.confsched2019.announcement.ui.actioncreator | |||
|
|
|||
| import androidx.lifecycle.Lifecycle | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 🚫 | Unused import |
| @@ -1,22 +1,23 @@ | |||
| package io.github.droidkaigi.confsched2019.sponsor.ui.actioncreator | |||
|
|
|||
| import androidx.lifecycle.Lifecycle | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 🚫 | Unused import |
|
|
||
| import androidx.annotation.IntDef | ||
|
|
||
| class ScreenLifecycle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは難しそうなので、とりあえずなくてもいいかもですね。。
| /** | ||
| * This implementation refers to https://github.com/Kotlin/kotlinx.coroutines/pull/760 | ||
| */ | ||
| fun ScreenLifecycle.createJob( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この実装の思想は「画面回転を跨いだ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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する
僕個人として、この考え自体には凄い賛成です。特にこのアプリはこの考えの恩恵をかなり受けられそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これの方式との比較が気になるという感じですかね?確かにAACのライフサイクル化よりそちらを先に考えたほうがいいかもですねー
https://qiita.com/kafumi/items/8a8764679df8646b764a
Issue
Overview (Required)
Links
Screenshot