Activity.runOnUiThread (Runnable)
View.post (Runnable)
View.postDelayed Runnable, long)
Masalan, View.post (Runnable) dan foydalanib, boshqa Thread ichidagi UI Thread-ga (masalan, ExampleThread) quyidagi ko’rinishda kirishingiz mumkin:
4-kod rasmiga ozgina o’zgartirish qildik va xato yo’q.
Thread bo’yicha umumiy misol
Asinxron jarayonni tushunish uchun kelilar bitta misol qilamiz.
activity_main.xml
MainActivity.java
MainActivity ichida DOWNLOAD IMAGE tugmachasini bosish orqali downloadImage() metodini chaqiradi. Ushbu metod DownloadImage yangi threadni boshlaydi.
DownloadImage Threadi rasmni tarmoq orqali yuklab oladi va uni ImageView-da ko’rsatadi va keyin Image Downloaded tushdi xabarini ko’rsatadi.
Eslatma: AndroidManifest faylini oching va tarmoq orqali rasm yuklab olish uchun INTERNET ruxsatini qo’shing.
Threadexample android dasturini ishga tushirishda quyidagi ko’rinishga ega bo’ladi:
manbaa : medium.com
muallif : Aziz Ismoilov
Do'stlaringiz bilan baham: |