Android: How to put an Enum in a Bundle?

前端 未结 12 1415
别那么骄傲
别那么骄傲 2020-12-22 16:56

How do you add an Enum object to an Android Bundle?

12条回答
  •  离开以前
    2020-12-22 17:31

    For Intent you can use this way:

    Intent : kotlin

    FirstActivity :

    val intent = Intent(context, SecondActivity::class.java)
    intent.putExtra("type", typeEnum.A)
    startActivity(intent)
    

    SecondActivity:

    override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState) 
         //...
         val type = (intent.extras?.get("type") as? typeEnum.Type?)
    }
    

提交回复
热议问题