Title: @Extra - generate public class fields for extras instead of hardcoding extra name · Issue #441 · androidannotations/androidannotations · GitHub
Open Graph Title: @Extra - generate public class fields for extras instead of hardcoding extra name · Issue #441 · androidannotations/androidannotations
X Title: @Extra - generate public class fields for extras instead of hardcoding extra name · Issue #441 · androidannotations/androidannotations
Description: What happens right now 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 cla...
Open Graph Description: What happens right now 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. ...
X Description: What happens right now 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 Activi...
Opengraph URL: https://github.com/androidannotations/androidannotations/issues/441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@Extra - generate public class fields for extras instead of hardcoding extra name","articleBody":"## What happens right now\n\nRight 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.\n## What should happen\n\nGenerate 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.\n## Code Examples\n### Base File\n\n``` java\n@EActivity\npublic class NewPostActivity extends SherlockFragmentActivity {\n @Extra\n String photoUri;\n}\n```\n### Generated\n\n``` java\n private void injectExtras_() {\n Intent intent_ = getIntent();\n Bundle extras_ = intent_.getExtras();\n if (extras_!= null) {\n if (extras_.containsKey(\"photoUri\")) {\n try {\n photoUri = cast_(extras_.get(\"photoUri\"));\n } catch (ClassCastException e) {\n Log.e(\"NewPostActivity_\", \"Could not cast extra to expected type, the field is left to its default value\", e);\n }\n }\n }\n }\n\npublic NewPostActivity_.IntentBuilder_ photoUri(String photoUri) {\n intent_.putExtra(\"photoUri\", photoUri);\n return this;\n }\n```\n### How it should be\n\n``` java\npublic static String photoUriExtra = \"photoUri\";\n\n private void injectExtras_() {\n Intent intent_ = getIntent();\n Bundle extras_ = intent_.getExtras();\n if (extras_!= null) {\n if (extras_.containsKey(photoUriExtra)) {\n try {\n photoUri = cast_(extras_.get(photoUriExtra));\n } catch (ClassCastException e) {\n Log.e(\"NewPostActivity_\", \"Could not cast extra to expected type, the field is left to its default value\", e);\n }\n }\n }\n }\n\npublic NewPostActivity_.IntentBuilder_ photoUri(String photoUri) {\n intent_.putExtra(photoUriExtra, photoUri);\n return this;\n }\n```\n### in a fragment\n\n``` java\n// before solving this issue\n// if extra's name changes this variable can be easily forgotten\nfinal String photoUriExtra = \"photoUri\"; \n\n// after change\nfinal String photoUriExtra = NewPostActivity_.photoUriExtra;\n```\n","author":{"url":"https://github.com/ironjan","@type":"Person","name":"ironjan"},"datePublished":"2012-12-26T19:28:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/441/androidannotations/issues/441"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:245e4ce7-5553-c3c9-0d74-20ac77b495d6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D84:1CC3A6:3C894:53575:6A628499 |
| html-safe-nonce | edb0c5c3092f70418d86c36a81dfda9b1b6187b7aeb9268a2a86accbc314cd83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDg0OjFDQzNBNjozQzg5NDo1MzU3NTo2QTYyODQ5OSIsInZpc2l0b3JfaWQiOiI4NzE3MzA5NTY3MDAzOTUyMjgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e6fd33da35de8c44627e0cea8ea5ac842fbfaac2c15b31323b3896e7bb66540b |
| hovercard-subject-tag | issue:9525680 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/androidannotations/androidannotations/441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5399919f4727bd27e3369af58dc3626de91e20311b84e5f66444ec4423dbaeaa/androidannotations/androidannotations/issues/441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5399919f4727bd27e3369af58dc3626de91e20311b84e5f66444ec4423dbaeaa/androidannotations/androidannotations/issues/441 |
| og:image:alt | What happens right now 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. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ironjan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7a4ef49a11a2c05de16a801b29c54a151d2e3262d6fd17381ca13b5ae25dda8f |
| turbo-cache-control | no-preview |
| go-import | github.com/androidannotations/androidannotations git https://github.com/androidannotations/androidannotations.git |
| octolytics-dimension-user_id | 1315313 |
| octolytics-dimension-user_login | androidannotations |
| octolytics-dimension-repository_id | 3116751 |
| octolytics-dimension-repository_nwo | androidannotations/androidannotations |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3116751 |
| octolytics-dimension-repository_network_root_nwo | androidannotations/androidannotations |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 97b18c8f1d2683a31995fd6e802daf9bf0d4d3f0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width