You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Right now AndroidAnnotations generates hardcoded strings when using @Extras. This leads to hardcoding the extra's name in Fragments that get the extra passed by an Activity.
What should happen
Generate a public class constant that holds the extra's name. This constant can be used in the generated activity instead of hardcoding and in fragments that get the extras passed.
privatevoidinjectExtras_() {
Intentintent_ = getIntent();
Bundleextras_ = intent_.getExtras();
if (extras_!= null) {
if (extras_.containsKey("photoUri")) {
try {
photoUri = cast_(extras_.get("photoUri"));
} catch (ClassCastExceptione) {
Log.e("NewPostActivity_", "Could not cast extra to expected type, the field is left to its default value", e);
}
}
}
}
publicNewPostActivity_.IntentBuilder_photoUri(StringphotoUri) {
intent_.putExtra("photoUri", photoUri);
returnthis;
}
How it should be
publicstaticStringphotoUriExtra = "photoUri";
privatevoidinjectExtras_() {
Intentintent_ = getIntent();
Bundleextras_ = intent_.getExtras();
if (extras_!= null) {
if (extras_.containsKey(photoUriExtra)) {
try {
photoUri = cast_(extras_.get(photoUriExtra));
} catch (ClassCastExceptione) {
Log.e("NewPostActivity_", "Could not cast extra to expected type, the field is left to its default value", e);
}
}
}
}
publicNewPostActivity_.IntentBuilder_photoUri(StringphotoUri) {
intent_.putExtra(photoUriExtra, photoUri);
returnthis;
}
in a fragment
// before solving this issue// if extra's name changes this variable can be easily forgottenfinalStringphotoUriExtra = "photoUri";
// after changefinalStringphotoUriExtra = NewPostActivity_.photoUriExtra;