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.
startActivityForResult in activity intent builder #270
Yes, we thought about that, the only problem is that startActivityForResult is a method that only exists on the Activity class, not on the Context class. So this basically means we'd have to create two IntentBuilder class per Activity class.
Hum, giving it a few more thoughts, it can't work this way. The fluid API pattern requires using self bounded generics, to be able to do something such as : intent(activity).flags(0).startForResult(42) : flags() is defined in the supertype and returns this, but this is an instance of supertype, unless we have it return T, T being a self bounded generic.
We could also go down the "unsafe but ok road", just add the following startForResult() method to the current implementation :
Yep, saw that. I don't know, if it is possible to make a compile-time warning, when we call startForResult from non activity context. One of the main feature of AA is compile-time checks, and i like that :)
@naixx Because "self bounded generics" are a nice nerdy things that 99% of java developers know nothing about, and would be scared to hell when seeing what Eclipse tell them about the return type of the intent() method :) .
We could have also created two IntentBuilder classes per activity, one that takes a context and one that takes an activity.
We cannot put a compilation warning on method calls. Only on compilation elements (ie declarations). We could log a warning at runtime if the context isn't an activity, I guess.
@pyricau, But developers would see only clean interface, which will or not have startForResult, they don't even need to know about internal IntentBuilder classes. But it will provide them much more safety.
I meant a runtime warning to the Log. In this case we need somehow to tell developer, that the program would not behave as expected(he will never receive a result). Probably even an exception could be thrown?
Although I like making my app crash in debug mode when something's unexpected, to force devs to fix it, I wouldn't enforce this in an open source framework :) . I think the runtime warning is a good enough solution.
Regarding the self bounded generic, the developer will use the autocompletion and see in the autocompletion doc that "intent()" returns a weird type and get scared :) . At least that's my theory.
Yes, it's possible but doesn't change a thing on the signature of methods implemented by IntentBuilder2 :) . The'll still return a IntentBuilder2<>, <>, with capture-of* adding a lot of noise :)
When you write MyActivity_.intent(context).flags(0) and let Eclipse show you the signature of the flags() method. This method belongs to IntentBuilder2<>, <>.
Ok, now i understand :) For me, its not so scary. Developer won't see this class in his own code, only auto-completion in IDE. There are a lot of generics in standard library and even android (e.g. Simple*Adapters), but people use them :).
Activity
pyricau commentedon Jul 12, 2012
Yes, we thought about that, the only problem is that startActivityForResult is a method that only exists on the
Activityclass, not on theContextclass. So this basically means we'd have to create two IntentBuilder class per Activity class.naixx commentedon Jul 12, 2012
Yep, missed that. Probably, it can be done smth like this, without generating fully same classes:
And additional static method in activity:
pyricau commentedon Jul 12, 2012
Yeah, that's an interesting solution. A few notes :
((Activity)context_).startActivityForResult(intent_, request);, that's the whole point of using generics here :) .startForResult()pyricau commentedon Jul 12, 2012
Hum, giving it a few more thoughts, it can't work this way. The fluid API pattern requires using self bounded generics, to be able to do something such as :
intent(activity).flags(0).startForResult(42):flags()is defined in the supertype and returnsthis, but this is an instance of supertype, unless we have it return T, T being a self bounded generic.We could also go down the "unsafe but ok road", just add the following
startForResult()method to the current implementation :Adding startForResult on activity intent builders. #270
naixx commentedon Jul 12, 2012
Haven't tried yet, but what do you think?
Probably, there is a solution for compile time checks.
pyricau commentedon Jul 13, 2012
Yeah, this is what I called "self bounded generics".
As you probably noticed, I just implemented a "simpler" solution in #271.
naixx commentedon Jul 13, 2012
Yep, saw that. I don't know, if it is possible to make a compile-time warning, when we call startForResult from non activity context. One of the main feature of AA is compile-time checks, and i like that :)
pyricau commentedon Aug 2, 2012
Agreed. However, for this specific case, I see no better solution.
naixx commentedon Aug 2, 2012
@pyricau, why don't you want to use "self bounded generics"?
The other issue, probably a warning should be, if we use startForResult with non activity code.
pyricau commentedon Aug 3, 2012
@naixx Because "self bounded generics" are a nice nerdy things that 99% of java developers know nothing about, and would be scared to hell when seeing what Eclipse tell them about the return type of the
intent()method :) .We could have also created two IntentBuilder classes per activity, one that takes a context and one that takes an activity.
We cannot put a compilation warning on method calls. Only on compilation elements (ie declarations). We could log a warning at runtime if the context isn't an activity, I guess.
naixx commentedon Aug 3, 2012
@pyricau, But developers would see only clean interface, which will or not have
startForResult, they don't even need to know about internalIntentBuilderclasses. But it will provide them much more safety.I meant a runtime warning to the
Log. In this case we need somehow to tell developer, that the program would not behave as expected(he will never receive a result). Probably even an exception could be thrown?pyricau commentedon Aug 3, 2012
Although I like making my app crash in debug mode when something's unexpected, to force devs to fix it, I wouldn't enforce this in an open source framework :) . I think the runtime warning is a good enough solution.
Regarding the self bounded generic, the developer will use the autocompletion and see in the autocompletion doc that "intent()" returns a weird type and get scared :) . At least that's my theory.
naixx commentedon Aug 3, 2012
@pyricau Didn't check, but what if:
So, we will have
ContextIntentBuilderandActivityIntentBuilderthat will be returned fromintent(). Is it possible in Java?Yep, warning would be good anyway.
pyricau commentedon Aug 3, 2012
Yes, it's possible but doesn't change a thing on the signature of methods implemented by IntentBuilder2 :) . The'll still return a
IntentBuilder2<>, <>, withcapture-of*adding a lot of noise :)naixx commentedon Aug 3, 2012
@pyricau Actually, i didn't clearly understand the problem.
IntentBuilder2<>, <>is hidden, so whats the noise?pyricau commentedon Aug 3, 2012
When you write
MyActivity_.intent(context).flags(0)and let Eclipse show you the signature of theflags()method. This method belongs toIntentBuilder2<>, <>.naixx commentedon Aug 3, 2012
Ok, now i understand :) For me, its not so scary. Developer won't see this class in his own code, only auto-completion in IDE. There are a lot of generics in standard library and even android (e.g. Simple*Adapters), but people use them :).