Faced such a task that you need to get the type of variable in one @IntDef , transfer it to another onActivityResult() via onActivityResult() .
The problem is that it is impossible to apply an explicit cast to this annotation, it cannot be serialized. If you create a field with getter \ setters, then the transfer returns an int (at best, sometimes you come across a String ).
int to @IntDef not applicable - because it is the basic principle and the whole salt of its use.
Let's say there is a certain @IntDef :
import android.support.annotation.IntDef; @IntDef({Importance.noMatter, Importance.green, Importance.yellow, Importance.red}) public @interface Importance { public static int noMatter = 0; public static int green = 1; public static int yellow = 2; public static int red = 3; } Then, to use it, it is enough to write @Importance.green - and the necessary int will go to the input parameter that expects, for example, the method.
If we use just a number, the compiler will not allow us to do this. And he will not allow us to make the following construction:
private Importance importance; public Importance getImportance() { return importance; } public void setImportance(Importance importance) { this.importance = importance; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == EDITING_REQUEST) { if (resultCode == RESULT_OK) { String importanceString = getIntent().getExtras().getString("importance"); switch (importanceString){ case "no_matter": setImportance(Importance.noMatter); break; } Thus, there are 2 options: either to artificially do something similar, complaining about the integrity of other developers, or to somehow solve this deadlock.
Of course, the first option is faster, but I still want to know if anyone has come across a similar one, or maybe I missed something \ didn’t see / misunderstood somewhere, and in fact there is a simple mechanism for this?
If Enum can at least be serialized as an object, I won’t attach my mind here.
As my good friend says - follow the path of a samurai.