Wednesday, 5 August 2020

Working with UI controls from Non main thread in Kotlin


import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread


fun anyFunction(){
doAsync {
      // Normal code inside Async thread
      I=I+1
     If(I=100){

    uiThread {

        tvResult.setText =”I is now 100!!”
      }
    }
   //More code
   If(x==0){
     uiThread {

        tvResult.setText =”there’s some problem!”
      }
   }


}
}

Note: - you can include multiple uiThread inside same doAsync
          - you can include multiple doAsync inside any function

No comments:

Post a comment

Unit test c#: Create Fake Httpcontext to bypass Null exception for User object

  Microsoft Visual studio Test Framework Requirement: Nuget package Moq 4.13.0.0 (or later) Settings in visual studio: Menu->Tools->Op...