Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to pack an enum value in a Bundle and get as enum

Tags:

android

I have this enum like this

  enum Status {READY, DISCONNECTED, RECEIVING, ... more }

I want to send a value of this enum over to another thread via a Bundle.

The other thread would like to extract enum value from the Bundle ,

How can this be done , smartly ?

   Bundle createBundle(Status status);

and

   Status getStatus(Bundle b);

Thanks,

like image 365
Ahmed Avatar asked Nov 14 '12 18:11

Ahmed


1 Answers

Since Enum is serializable, we can just pack the enum into the bundle using:

public static String MY_ENUM = "MY_ENUM";
myBundle.putSerializable(MY_ENUM, enumValue);

To retrieve, use:

MyEnum myEnum = (MyEnum) myBundle.getSerializable(MY_ENUM);
like image 164
mutexkid Avatar answered Nov 16 '22 02:11

mutexkid