Guest User

Untitled

a guest
Apr 7th, 2020
171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import android.os.Bundle
  3. import android.util.Log
  4. import androidx.appcompat.app.AppCompatActivity
  5. import io.reactivex.Flowable
  6. import io.reactivex.Single
  7. import io.reactivex.disposables.Disposable
  8. import io.reactivex.functions.BiFunction
  9. import io.reactivex.schedulers.Schedulers
  10. import java.util.concurrent.TimeUnit
  11.  
  12. class MainActivity : AppCompatActivity() {
  13.     private lateinit var disposable: Disposable
  14.     override fun onCreate(savedInstanceState: Bundle?) {
  15.         super.onCreate(savedInstanceState)
  16.         setContentView(R.layout.activity_main)
  17.     }
  18.  
  19.     override fun onStart() {
  20.         super.onStart()
  21.         disposable = Single.fromCallable(this::longOperation)
  22.             .subscribeOn(Schedulers.io())
  23.             .subscribe()
  24.     }
  25.  
  26.     override fun onStop() {
  27.         super.onStop()
  28.         disposable.dispose()
  29.     }
  30.  
  31.     private fun longOperation() {
  32.         for (n in 0 until 1_000_000) {
  33.             Log.d("MainActivity", n.toString())
  34.             Thread.sleep(10)
  35.         }
  36.     }
  37. }
RAW Paste Data