Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disposing on Android 3
class MainActivity : AppCompatActivity() {
private lateinit var textView: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView = findViewById(R.id.text_view)
}
override fun onStart() {
super.onStart()
// Example 1
DummyNetwork.query()
.subscribe(::displayResponse)
.disposeBy(onStop)
// Example 1 (Verbose)
DummyNetwork.query()
.subscribe(::displayResponse)
.disposeBy(lifecycle.disposers.onStop)
// Example 2
onStop += DummyNetwork.query()
.subscribe(::displayResponse)
// Example 2 (Verbose)
lifecycle.disposers.onStop += DummyNetwork.query()
.subscribe(::displayResponse)
}
private fun displayResponse(response: String) {
textView.text = response
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment