Skip to content

Instantly share code, notes, and snippets.

@BuiVanNam
Last active December 2, 2020 15:22
Show Gist options
  • Save BuiVanNam/1216ca5fda1acad4bec0ee3215934b2c to your computer and use it in GitHub Desktop.
Save BuiVanNam/1216ca5fda1acad4bec0ee3215934b2c to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
var objectA = null
override fun onCreate(savedInstanceState: Bundle?) {
////
initObjectA()
}
override fun onResume() {
super.onResume()
registerListenerAChange()
}
override fun onStop() {
super.onStop()
unRegisterListenerAChange()
}
override fun onDestroy() {
super.onDestroy()
releaseAll()
}
private fun initObjectA() {
objectA = getAFromFrameworkApi()
}
private fun registerListenerAChange() {
objectA.registerStateChange()
}
private fun unRegisterListenerAChange() {
objectA.unregister()
}
private fun releaseAll() {
objectA.release()
objectA = null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment