Title: Fix IntentBuilder startForResult by tbruyelle · Pull Request #680 · androidannotations/androidannotations · GitHub
Open Graph Title: Fix IntentBuilder startForResult by tbruyelle · Pull Request #680 · androidannotations/androidannotations
X Title: Fix IntentBuilder startForResult by tbruyelle · Pull Request #680 · androidannotations/androidannotations
Description: Related to #541 In a fragment, startActivityForResult must be called on the Fragment and not on getActivity(), or the fragment's onActivityResult will never be hit. Now IntentBuilder may have up to 3 constructors, depending on the classpath content. According to the constructor chosen, startActivityForResult() will be called on Activity, android.app.Fragment or android.support.v4.app.Fragment. From the AA user perspective, this fix is quite transparent, he just have to call MyActivity_.intent(this), whatever he's in a fragment or an activity, it will work. Generated code in case of both android.app.Fragment and android.support.v4.Fragment are presents in the classpath (true for current AA junit environment) : public static ExtendingActivity_.IntentBuilder_ intent(Context context) { return new ExtendingActivity_.IntentBuilder_(context); } public static ExtendingActivity_.IntentBuilder_ intent(android.app.Fragment fragment) { return new ExtendingActivity_.IntentBuilder_(fragment); } public static ExtendingActivity_.IntentBuilder_ intent(android.support.v4.app.Fragment fragment) { return new ExtendingActivity_.IntentBuilder_(fragment); } public static class IntentBuilder_ { private Context context_; private final Intent intent_; private android.app.Fragment fragment_; private android.support.v4.app.Fragment fragmentSupport_; public IntentBuilder_(Context context) { context_ = context; intent_ = new Intent(context, ExtendingActivity_.class); } public IntentBuilder_(android.app.Fragment fragment) { fragment_ = fragment; context_ = fragment.getActivity(); intent_ = new Intent(context_, ExtendingActivity_.class); } public IntentBuilder_(android.support.v4.app.Fragment fragment) { fragmentSupport_ = fragment; context_ = fragment.getActivity(); intent_ = new Intent(context_, ExtendingActivity_.class); } public Intent get() { return intent_; } public ExtendingActivity_.IntentBuilder_ flags(int flags) { intent_.setFlags(flags); return this; } public void start() { context_.startActivity(intent_); } public void startForResult(int requestCode) { if (fragmentSupport_!= null) { fragmentSupport_.startActivityForResult(intent_, requestCode); } else { if (fragment_!= null) { fragment_.startActivityForResult(intent_, requestCode); } else { if (context_ instanceof Activity) { ((Activity) context_).startActivityForResult(intent_, requestCode); } else { context_.startActivity(intent_); } } } } } Notes : I didn't find proper method to test if a class is present in the classpath. so I used Class.forName(). Tell me if I miss something. I tested the feature in a test project, and the generated code is well updated according to android.app.Fragment or android.support.v4.app.Fragment are present or not in the classpath. But I didn't manage to create a junit for that. The only tests I wrote are compile tests with fragments class which use the new intent() methods.
Open Graph Description: Related to #541 In a fragment, startActivityForResult must be called on the Fragment and not on getActivity(), or the fragment's onActivityResult will never be hit. Now IntentBuilder may have u...
X Description: Related to #541 In a fragment, startActivityForResult must be called on the Fragment and not on getActivity(), or the fragment's onActivityResult will never be hit. Now IntentBuilder may ha...
Opengraph URL: https://github.com/androidannotations/androidannotations/pull/680
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c9798cbf-4d26-9bad-d0ef-8eca77101c51 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E0E0:2D823:1012B57:167E607:6A61B892 |
| html-safe-nonce | ab4429b607b6ebd4050d212d659a62e32bd6bb4f0f3dddf121ee2561d7d36002 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEUwOjJEODIzOjEwMTJCNTc6MTY3RTYwNzo2QTYxQjg5MiIsInZpc2l0b3JfaWQiOiI0OTI1MDE4MDc1MDI3MzIzMDI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b3b3ea0a94eb8da437c74920dd79e7eab7f7fd2723af4687a7abbe5635fd227a |
| hovercard-subject-tag | pull_request:7194451 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/androidannotations/androidannotations/pull/680/files |
| twitter:image | https://avatars.githubusercontent.com/u/92280?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/92280?s=400&v=4 |
| og:image:alt | Related to #541 In a fragment, startActivityForResult must be called on the Fragment and not on getActivity(), or the fragment's onActivityResult will never be hit. Now IntentBuilder may have u... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width