1

I'm trying to create a Enum STATE pattern so I can set the current state of my operations. In C# (i think) I used this pattern:

Enum State { STARTED, STOPPED, PAUSED };
State _s;

public foo() {
   _s = State.STARTED;
}

I did read somewhere that you shouldn't or couldn't use Enum in Android. How can I replicate this design pattern in Android?

jaco0646
  • 13,332
  • 7
  • 54
  • 75
aelveborn
  • 317
  • 1
  • 3
  • 16
  • Enums are slightly less efficient than ints, but it probably won't be a big enough difference to matter. Is that what you were referring to? – noisecapella Aug 11 '12 at 22:05
  • 3
    I'm not so sure that you can't use enums for Android. That information might be obsolete due to performance gains of the VM: http://stackoverflow.com/questions/5143256/why-was-avoid-enums-where-you-only-need-ints-removed-from-androids-performanc – Blacklight Aug 11 '12 at 22:07
  • Okey, that actually answerd my question. Thanks alot @Blacklight – aelveborn Aug 11 '12 at 22:12

1 Answers1

1

You definitely can use them. Android's libraries don't which probably perpetuates the myth/out of date advice. It's easy to switch from one to the other, so start with enums and only change if you experience performance issues, but I doubt you will.

weston
  • 52,585
  • 20
  • 135
  • 197
  • 1
    Yes it worked like a charm. For future readers: `private static enum State {STARTED, STOPPED, RESETED}; private State state;` and to set the state `state = State.STARTED;` – aelveborn Aug 11 '12 at 22:32