Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (2.6k points)

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

1 Answer

0 votes
by (46k points)

Enums are Serializable so there is no problems.

Given this enum:

enum YourEnum {

  TYPE1,

  TYPE2

}

Bundle:

// put

bundle.putSerializable("key", YourEnum.TYPE1);

// get 

YourEnum yourenum = (YourEnum) bundle.get("key");

Intent:

// put

intent.putExtra("key", yourEnum);

// get

yourEnum = (YourEnum) intent.getSerializableExtra("key");

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 23, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 25, 2019 in Java by Anvi (10.2k points)

Browse Categories

...