I am working on a simple app that requires data from a URL call. Here are the relevant code parts
class NewsFeed : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_news_feed)
lifecycleScope.launchWhenCreated {
getNewsData()
}
private suspend fun getNewsData() {
withContext(Dispatchers.IO) {
try {
val jObj = Jsoup.connect(getString(R.string.news_feed)).get()
//many non relevant lines
BitmapFactory.decodeByteArray(URL(img).readBytes(), 0, 0)
The IDE gives a warning on both .get() and URL() methods saying it is a "inappropriate thread-blocking method call"
However if I understand correctly I am in a Dispacher.IO coroutine scope and the job is being done on a different thread created for blocking tasks. App does not crush or block the UI even if I timeout the calls.
Except suppressing the warning, what am I doing wrong?