Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val observable = Observable
- .just(longRunningOperation())
- btStartOperation.setOnClickListener {
- observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
- { text -> Toast.makeText(this, text, Toast.LENGTH_SHORT).show() },
- { error -> error.printStackTrace() },
- { /*Toast.makeText(this, "complete", Toast.LENGTH_SHORT).show()*/ }
- )
- }
- }
- private fun longRunningOperation(): String {
- return try {
- Thread.sleep(5000)
- "Mantap bos!"
- } catch (e: InterruptedException) {
- e.printStackTrace()
- "ga mantap ah"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment