Created
April 26, 2021 16:13
-
-
Save andreyfomenkov/4143c0cdee3563d7af8009c6e6ac6080 to your computer and use it in GitHub Desktop.
Dispose a resource [A]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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