Skip to content

Instantly share code, notes, and snippets.

@andreyfomenkov
Created April 26, 2021 16:13
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 andreyfomenkov/4143c0cdee3563d7af8009c6e6ac6080 to your computer and use it in GitHub Desktop.
Save andreyfomenkov/4143c0cdee3563d7af8009c6e6ac6080 to your computer and use it in GitHub Desktop.
Dispose a resource [A]
class WeatherActivity : AppCompatActivity() {
private val thermometer = Thermometer.getInstance()
private var disposable: Disposable? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
disposable = thermometer
.observeTemperature()
.subscribe { celsius -> /* Display in a TextView */ }
}
overrie fun onDestroy() {
disposable?.apply { dispose() } // Release
super.onDestroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment