Канал необратимо поврежден и будет удален!
и
Не удалось открыть APK '/data/app...
и
не удалось добавить путь к ресурсу /data/app
Вот код из MainActivity:
Код: Выделить всё
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val tv = findViewById(R.id.tv)
val button = findViewById(R.id.button)
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://dummyjson.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
val productApi = retrofit.create(ApiService::class.java)
button.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
val product = productApi.getProductById()
runOnUiThread {
tv.text = product.title
}
}
}
}
}
Код: Выделить всё
interface ApiService {
@GET("products/1")
suspend fun getProductById(): Product
}
Код: Выделить всё
data class Product(
val id: Int,
val title: String,
val description: String,
val price: Int,
val discountPercentage: Float,
val rating: Int,
val stock: Float,
val brand: String,
val category: String,
val thumbnail: String,
val images: List,
)
Подробнее здесь: https://stackoverflow.com/questions/784 ... e-disposed