Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- build
- 깃헙
- Gradle
- 코루틴
- coroutine
- error
- 코틀린
- ADB
- 안드로이드
- 안드로이드 스튜디오
- WebView
- viewpager
- 안드로이드스튜디오
- Retrofit
- 스튜디오
- 유튜브
- image
- RecyclerView
- Kotlin
- 에러
- studio
- MVVM
- Android
- 레트로핏
- dart
- GIT
- 의존성주입
- 웹뷰
- Github
- 안스
Archives
- Today
- Total
코딩하는 일용직 노동자
Koin sharedViewModel deprecated. 이제부터는 activityViewModel을 사용하세요. 본문
안드로이드 의존성주입에 Koin을 사용할때 Activity 와 그 아래 속한 하나 이상의 Fragment 에서
같은 ViewModel 을 사용할 필요가 있는 경우가 있습니다.
기존에는 by sharedViewModel() 을 이용하면 됐는데 이것이 deprecated 되었습니다.
이제는 by activityViewModel() 을 이용하도록 변경되었습니다.
val weatherAppModule = module {
// WeatherViewModel declaration for Weather View components
viewModel { WeatherViewModel(get(), get()) }
}
class WeatherActivity : AppCompatActivity() {
/*
* Declare WeatherViewModel with Koin and allow constructor dependency injection
*/
private val weatherViewModel by viewModel<WeatherViewModel>()
}
class WeatherHeaderFragment : Fragment() {
/*
* Declare shared WeatherViewModel with WeatherActivity
*/
private val weatherViewModel by activityViewModel<WeatherViewModel>()
}
class WeatherListFragment : Fragment() {
/*
* Declare shared WeatherViewModel with WeatherActivity
*/
private val weatherViewModel by activityViewModel<WeatherViewModel>()
}
자세한 내용은 아래 링크를 확인하시면 됩니다.
Android ViewModel & Navigation | Koin
The koin-android Gradle module introduces a new viewModel DSL keyword that comes in complement of single and factory, to help declare a ViewModel
insert-koin.io
'안드로이드' 카테고리의 다른 글
GoogleCloud Git - permission denied (publickey) 문제 해결 (2) | 2023.05.22 |
---|---|
adb command not found 수정하는 방법. (1) | 2023.05.10 |
SHA1 키 알아내기. (0) | 2023.03.06 |
새로운 크로스 플랫폼 Kotlin Multiplatform Mobile (1) | 2022.10.14 |
앱용 아이콘 이미지 제공 사이트 & 해상도별 이미지 생성 사이트 (0) | 2022.09.18 |