Glide Error - You cannot start a load for a destroyed activity

Glide 관련 된 처음보는 오류가 발생했다. You cannot start a load for a destroyed activity 다행히(?) 예전에 이슈가 된 에러였다.(https://github.com/bumptech/glide/issues/803) 이런 에러가 발생한 이유는 with() 함수가 lifecycle을 따르기 때문이다. 즉 Glide가 이미지가 로드 중 Glide.with()의 with()에 들어간 인자가 “activity 또는 fragment가 destroyed"되면서 영향을 받게 되고 위의 에러가 발생한 것으로 보입니다. 스택오버플로우에서 제안하는 방법으로는 아래와 같이 RequestManager를 변수에 담아주고 사용하는 것이다. class MyAdapter extends WhichEveryOneYouUse { private final RequestManager glide; MyAdapter(RequestManager glide, ...) { this.glide = glide; ... } void getView/onBindViewHolder(... int position) { // ... holder magic, and get current item for position glide.load... or even loadImage(glide, item.url, holder.image); } } loadImage(Glide.with(this), url, findViewById(R.id.image)); // or list.setAdapter(new MyAdapter(Glide.with(this), data)); Reference ...

2020년 5월 14일 · 1 분 · Maru

[Maru의 Kotlin Tour - 공식 문서 편] #3 Returns and Jumps

kotlin에는 3가지 jump 표현식이 있다. return : 제일 가까운 enclosing function으로 부터 return 합니다. break : 제일 가까운 enclosing loop를 종료합니다. continue : 제일 가까운 enclosing loop의 다음 단계(step)를 진행합니다. Break and Continue Labels Kotlin의 어떤 표현이든 label을 붙일 수 있다. @을 붙여서 라벨을 만들 수 있는데, 아래와 같이 쓰인다. loop@ for (i in 1..100){ // ... } 이제, break에 label을 붙이면 아래와 같이 쓸 수 있는데 loop@ for (i in 1..100){ for (j in 1..100){ if (...) break@loop } } 위의 코드 같은 경우는 break@loop에서 loop@로 점프 한 후 바로 다음 코드가 실행 된다고 한다. continue 같은 경우는 loop의 다음 반복자가 실행 된다고 한다. ...

2020년 2월 5일 · 4 분 · Maru

[Maru의 Kotlin Tour - 공식 문서 편] #2 Control Flow

If Expression if는 expression, 즉 값을 return 하므로 tenary operator(condition ? then : else)가 없다고 한다.(난 tenary operator 좋은데..) 그럼 if 표현식을 보자 // Traditional usage var max = a if (a < b) max = b // With else var max: Int if (a > b) { max = a } else { max = b } // As expression val max = if (a > b) a else b 마지막 코드인 val max = if (a > b) a else b가 tenary operator와 비슷해보인다. ...

2020년 2월 2일 · 2 분 · Maru

[Maru의 Kotlin Tour - 공식 문서 편] #1 Basic Types

해당 문서 첫 문장에 참 친근한 문장이 있다. In Kotlin, everything is an object 그래서 모든 변수에서 member function과 properties를 부를 수 있다고 한다. 이 섹션에서는 numbers, characters, booleans, arrays, 그리고 strings을 다룬다. Numbers Kotlin에서 integer는 총 4가지, floating은 총 2가지 타입을 제공해준다. Integer Byte Short Int Long val one = 1 // Int val threeBillion = 300000000 // Long val oneLong = 1L // Long val oneByte: Byte = 1 위의 코드에서 주목해야 할 점은 threeBillioin 변수이다. ...

2020년 2월 2일 · 5 분 · Maru

[Maru의 Kotlin Tour - 공식 문서 편] #0 Intro

들어가기 앞서 코틀린의 정의와 Command Line Compiler를 설치하는 법을 알아보겠습니다. 코틀린의 정의 코틀린(Kotlin)은 JVM에서 동작하는 프로그래밍 언어이다. 2011년 7월, 젯브레인사가 공개하였다. 캇린으로 읽어야 한다. (캇린으로 읽어야 하는 것은 처음 알았습니다;;) Install Command Line Compiler Kotlin으로 작성한 파일을 실행하기 위해서는 몇 가지 방법을 Tutorial Getting Start에서 제안합니다. 저는 여기서 Working with the Command Line Compiler 방법을 선택 했습니다. 설치 방법도 여러가지 입니다. 저는 OS X를 사용하기 때문에 HomeBrew를 이용해서 설치하겠습니다. 다른 방법들은 문서를 참고 해주세요 $ brew update $ brew install kotlin ...

2020년 2월 2일 · 2 분 · Maru