0 votes
1 view
in Java by (2.6k points)

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

1 Answer

0 votes
by (46.1k 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 Aug 7, 2019 in Java by Nigam (4.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...