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.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
using IntentBuilder and startForResult in Fragment #541
when using the IntentBuilder and startForResult in a Fragment the startAcitivityForResult is called on the activity and not the Fragment. That results in onActivityResult is called on Result for the Activity and not the Fragment. Not sure how to solve this as the IntentBuilder does not have the reference to the calling fragment - perhaps the startForResult should have a target parameter - or you can give a fragment to .intent() instead of only a activity.
@mathieuboniface thanks for the quick reply & yes the problem is still there with 2.7.1 ( just tested ) was using 2.7 before
the problem is this generated code:
public void startForResult(int requestCode) {
if (context_ instanceof Activity) {
((Activity) context_).startActivityForResult(intent_, requestCode);
} else {
context_.startActivity(intent_);
}
}
there should be a way to do startActivityForResult on the Fragment and not on the Activity for encapsulation
Maybe more explanations are required here.
A fragment can override the onActivityResult() method, but to make it work, the activity must be started with Fragment.startActivityForResult(). If the activity is started with Activity.startActivityForResult(), then the method is never hit, which is the case when you start an activity with the AA IntentBuilder.
As @ligi suggested, a modification in the IntentBuilder is required. The constructor should allow a Fragment (the context attribute can be populated with Fragment.getActivity()). If so, startActivityForResult() will be called on the fragment rather than on the activity.
To not break the API we should add a new method startForResultFromFragment.
It would be nicer to handle that in startForResult but some applications will not works anymore with this.
It would be nicer to handle that in startForResult but some applications will not works anymore with this.
Not sure because current usage of IntentBuilder in fragments uses the constructor with the Context, so startForResult() will still call Activity.startActivityForResult(). Only IntentBuilder built with fragment rather than context will use Fragment.startActivityForResult().
I'm currently trying to implement a fix for this issue, by adding a new constructor for the IntentBuilder.
But I'm facing a problem, the need of import the Fragment class in the extended activity, which causes error on projects built under sdk<11 and which doesn't ship the support library.
How do you handle such things AA guys?
I could test if the Fragment class is present in the classpath (first the support version, then the standard version) and enable the feature only in that case. But I wonder how to write a test that ensure such feature. It would need 2 versions of the sdks, plus the support library...
About what I started to code, this is now how the IntentBuilder looks like, if both android.app.Fragment and android.support.v4.app.Fragment are present in the classpath :
I used the OnBackPressedApiDependenciesTest for my test, but still looking for a solution to write a real test on this feature.
Activity
mathieuboniface commentedon Mar 26, 2013
Hi @ligi,
Thank you for reporting that issue.
Which version of AndroidAnnotations are you using ?
We just provided a fix related to
@OnActivityResulton 2.7.1. You can have a look to #381 for more informations.ligi commentedon Mar 27, 2013
@mathieuboniface thanks for the quick reply & yes the problem is still there with 2.7.1 ( just tested ) was using 2.7 before
the problem is this generated code:
there should be a way to do startActivityForResult on the Fragment and not on the Activity for encapsulation
T12E commentedon Jun 6, 2013
Maybe more explanations are required here.
A fragment can override the
onActivityResult()method, but to make it work, the activity must be started withFragment.startActivityForResult(). If the activity is started withActivity.startActivityForResult(), then the method is never hit, which is the case when you start an activity with the AAIntentBuilder.As @ligi suggested, a modification in the
IntentBuilderis required. The constructor should allow aFragment(the context attribute can be populated withFragment.getActivity()). If so,startActivityForResult()will be called on the fragment rather than on the activity.DayS commentedon Jun 6, 2013
To not break the API we should add a new method
startForResultFromFragment.It would be nicer to handle that in
startForResultbut some applications will not works anymore with this.T12E commentedon Jun 7, 2013
Not sure because current usage of
IntentBuilderin fragments uses the constructor with the Context, sostartForResult()will still callActivity.startActivityForResult(). OnlyIntentBuilderbuilt with fragment rather than context will useFragment.startActivityForResult().tbruyelle commentedon Jun 9, 2013
I'm currently trying to implement a fix for this issue, by adding a new constructor for the
IntentBuilder.But I'm facing a problem, the need of import the
Fragmentclass in the extended activity, which causes error on projects built under sdk<11 and which doesn't ship the support library.How do you handle such things AA guys?
I could test if the
Fragmentclass is present in the classpath (first the support version, then the standard version) and enable the feature only in that case. But I wonder how to write a test that ensure such feature. It would need 2 versions of the sdks, plus the support library...Fix androidannotations#541 startActivityForResult called on Fragment
Fix androidannotations#541 startActivityForResult called on Fragment
tbruyelle commentedon Jun 9, 2013
About what I started to code, this is now how the
IntentBuilderlooks like, if bothandroid.app.Fragmentandandroid.support.v4.app.Fragmentare present in the classpath :I used the
OnBackPressedApiDependenciesTestfor my test, but still looking for a solution to write a real test on this feature.Fix androidannotations#541 startActivityForResult called on Fragment
Fix androidannotations#541 startActivityForResult called on Fragment
DayS commentedon Sep 20, 2013
Merged.
Add test to verify onActivityResult gets called in enhanced Fragments
Add test to verify onActivityResult gets called in enhanced Fragments