https://kotlinlang.org logo
#android
Title
# android
m

Mike Palarz

11/21/2018, 10:58 PM
Hey all! I have a coroutines question that I've been struggling with. I am making a network request in the following way:
fun fetchCharacterData(): Deferred<CharacterGenerator.CharacterData> {
return GlobalScope.async(Dispatchers.Default) {
val apiData = URL(CHARACTER_DATA_ENDPOINT).readText()
CharacterGenerator.fromApiData(apiData)
}
}
Then, in my main activity, I do the following within `onCreate()`:
generateButton.setOnClickListener {
GlobalScope.launch(Dispatchers.Main){
characterData = fetchCharacterData().await()
displayCharacterData()
}
}
However, I am getting an ANR whenever the button is pressed. I also get a very vague error message in logcat: FATAL EXCEPTION: main. Would anyone have any insight as to what the issue could be?
c

Chainchelliah

11/22/2018, 8:09 AM
ask your this question #coroutines here
m

Mike Palarz

11/23/2018, 8:37 PM
Thanks @Chainchelliah! Getting much more help now in that channel, appreciate the guidance 🙂
👍 1
3 Views