Skip to content

Instantly share code, notes, and snippets.

@sellmair
Created September 30, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sellmair/cd56842eb7f5c78522f6ae562cac646f to your computer and use it in GitHub Desktop.
Save sellmair/cd56842eb7f5c78522f6ae562cac646f to your computer and use it in GitHub Desktop.
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