Hey all! I have a coroutines question that I've be...
# android
m
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
ask your this question #coroutines here
m
Thanks @Chainchelliah! Getting much more help now in that channel, appreciate the guidance 🙂
👍 1