Last active
October 24, 2023 19:59
-
-
Save af2905/6614f9aef7f1868d1a175719a2e44138 to your computer and use it in GitHub Desktop.
receive_data_on_ui_thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private lateinit var binding: ActivityMainBinding | |
@OptIn(ExperimentalTime::class) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
this.runOnUiThread { | |
val (result: String, duration: Duration) = measureTimedValue { receiveData() } | |
Log.d("TAG", "$result after ${duration.toDouble(DurationUnit.MILLISECONDS)} ms.") | |
showToast(context = this, message = result) | |
} | |
Log.d("TAG", "onCreate completed") | |
} | |
private fun showToast(context: Context, message: String) { | |
val toast = Toast.makeText(context, message, Toast.LENGTH_SHORT) | |
toast.show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment