본문 바로가기
[coroutine] java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' [coroutine] java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' -coroutine 을 사용한 project 에서 release build (minify 포함) 을 하면 아래와 같은 exception 이 발생하며 crash 가 발생한다.java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotl.. 2019. 3. 6.
[coroutine] exception 을 이해해보자 #2 ( in global scope ) -[coroutine] exception 을 이해해보자 #1 ( in my coroutine scope ) 과 동일한 sample 들을 직접 생성한 coroutine 이 아닌 GlobalScope 에서 수행해보기로 했다.혹시나 뭔가 동작이 다를까 해서..내가 알고 있기로는 GlobalScope 은 defaultHandler 가 setting 되어 결국 모든 exception 을 먹어 crash 가 나지 않는다는 차이만 있는것으로 알고 있는데.. 검증해보자 ( 결론은 잘못 알고 있었다. ) -class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState).. 2019. 3. 6.
[coroutine] exception 을 이해해보자 #1 ( in my coroutine scope ) -이 글은 coroutine exception 에 대한 일종의 심화과정이라고 볼 수 있다.기본 exception 에 대한 내용을 먼저 이해한 후 이곳의 글을 보자![coroutine] Exception handling -class MainActivity : Activity() { private val coroutineScope = CoroutineScope(Dispatchers.Main) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) findViewById(R.id.btn).setOnClickListener { try { co.. 2019. 3. 5.
[coroutine] Exception handling Exception propagation - Coroutine builder 는 2가지 flavor 가 있다. exception 을 자동으로 전파하는 launch, actor류. 그리고 user 에게 노출되는 async, produce 류. 자동 전파하는 케이스는 Java 의 uncaughtExceptionHandler 와 비슷하게 unhandled exception 이다. 반면에 user 에게 노출되는 경우는 user 가 exception 을 직접 handle 할 수 있다. (돼왕: try-catch 할 수 있다.) 대표적 api 는 await 와 receive 가 있다. - runBlocking{ val job = GlobalScope.launch{ println(“Throwing exception f.. 2019. 3. 4.
[Coroutine] Coroutine context and dispatchers https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/coroutine-context-and-dispatchers.md#thread-local-data -기존에 있었던 doc 이 update 되어서 따로 정리한다. Coroutine context and dispatchers -Coroutine 은 항상 어떤 context 하에서 실행된다.이 context 는 CoroutineContext type 을 가지며 Kotlin standard lib 에 정의되어 있다. -Coroutine context 는 여러개의 element 들을 가진 set 이다.main element 는 coroutine 의 Job, dispatcher 이다. Dispatchers.. 2019. 2. 8.
[android] AsyncTask 를 Coroutine 으로 바꿔본 후기 -일반적으로 잘 사용하는 아래의 패턴은 꽤 나이스하게 바뀐다. onPreExecute 에서 progressdoInBackground 에서 bg jobonPostExecute 에서 progress 닫고 UI 작업 -// AsyncTask object : AsyncTask() { override fun onPreExecute() { showProgress(R.string.loading) } override fun doInBackground(vararg params: Void): List { return getMyAccountItemList(); } override fun onPostExecute(result: List) { if (isFinishing) return hideProgress() updateUI.. 2019. 2. 7.
[도서 정리] Android Development with Kotlin - Delegates Android Development with Kotlin - Delegates 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -class WitcherPlayer(enemy: String) : Player by RpgGamePlayer(enemy){ } 위 코드를 통해 Player 에 정의된 Delegate 가능한 모든 method 는 RpgGamePlayer 로 delegate 가 된다.단, implemented 된 녀석은 delegate 되지 않는다.RpgGamePlayer 는 init 타임에 instantiate 가 된다. 아래와 .. 2018. 12. 17.
[도서 정리] Android Development with Kotlin - Extension Functions and Properties Android Development with Kotlin - Extension Functions and Properties 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -extension function 들도 inline 가능하다. -extension function 과 같은 이름의 member function 이 있다면,항상 member function 이 우선순위를 갖는다.여기서 member function 이라 하면 super class 에 있는 member function 들도 해당한다. 이 말은 extension functio.. 2018. 12. 16.
[도서 정리] Android Development with Kotlin - Generics Are Your Friends Android Development with Kotlin - Generics Are Your Friends 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다. 제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ - Kotlin 에서 generics 는 기본적으로는 invariant 이다. invariant 는 subtyping relation 이 없다는 것 - generic 에서 subtyping 관계가 유지되는 것을 co-variant 라고 하고, 반대로 유지되는 것을 contra-variant. 그리고 유지되지 않는 것을 invariant 라고 한다. - Java 의 upper bound.. 2018. 12. 15.
반응형