Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created February 14, 2018 14:43
Show Gist options
  • Save EmmanuelGuther/349bff6d0c663331212e51ae6c4aff8d to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/349bff6d0c663331212e51ae6c4aff8d to your computer and use it in GitHub Desktop.
How to pass and retrieve a ENUM value in an intent
class HomeActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
}
private fun goToActivity(){
startActivity<MyActivity>(Constants.DEVICE_TYPE_TAG to deviceType)
}
}
class MyActivity : AppCompatActivity(){
private var deviceType: DeviceType? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_my)
deviceType = intent.getSerializableExtra(Constants.DEVICE_TYPE_TAG) as DeviceType
}
}
enum class DeviceType { ALPHA, BETA }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment