Intellipaat 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
2 answers
asked Nov 23, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
2 answers
asked Nov 25, 2019 in Java by Anvi (10.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...