I used to define a set of related constants like Bundle
keys together in an interface like below:
public interface From{
String LOGIN_SCREEN = "LoginSCreen";
String NOTIFICATION = "Notification";
String WIDGET = "widget";
}
This provides me a nicer way to group related constants together and used them by making a static import (not implements). I know Android
framework also uses the constants in same way like Toast.LENTH_LONG
, View.GONE
.
However, I often feel that the Java Enums
provide much better and powerful way to represent the constant.
But is there a performence issue in using enums
on Android
?
With a bit of research I ended up in confusion. From this question
"Avoid Enums Where You Only Need Ints” removed from Android's performance tips? it's clear that Google
has removed "Avoid enums" from its performance tips, but from it's official training docs Be aware of memory overhead section it clearly says: "Enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android." Is this still holds good? (say in Java
versions after 1.6)
One more issue that I observed is to send enums
across intents
using Bundle
I should send them by serializing (i.e putSerializable()
, that I think an expensive operation compared to primitive putString()
method, eventhough enums
provides it for free).
Can someone please clarify which one is the best way to represent the same in Android
? Should I strictly avoid using enums
on Android
?