Created
February 14, 2018 14:43
-
-
Save EmmanuelGuther/349bff6d0c663331212e51ae6c4aff8d to your computer and use it in GitHub Desktop.
How to pass and retrieve a ENUM value in an intent
This file contains hidden or 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 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