Repository navigation
Add support for Bundle parameter when starting activity #1027
Description
Activity
I must be retarded :) I which support class is there support for this ?
In Activity (actual definition comes from Context) and also supported in
the support library. There are overloads of all the start activity methods
that take a Bundle parameter. See
http://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent,
android.os.Bundle) for example. The ActivityOptions (and
ActivityOptionsCompat) class is how you build the bundle.The simplest implementation would be to add additional overloads of the
start methods that take the bundle parameter. A more advanced option would
be to have a withOptions method in the builder that takes the bundle and
the implementation of the start methods courses the correct method based on
whether the options were set.This is related to the withAnimation method I also proposed in that they
both can have the same effect for setting animation, but there are reasons
for having both options. You are also future proofing for when they might
add additional options.I agree, we should support bundle parameters in the
start()method.@dalewking @DayS @yDelouis do you thought abut this?
MyActivity_.intent(this).bundle(options).start();
@WonderCsabo That is the equivalent of the withOptions method I suggested only difference being the method name. You went with the type of the parameter and I went with the parameter name.
OK,
withOptionsis better.However, we cannot implement this in our static API, since we link against an older Android SDK, and also the support jar is not a dependency, so we must generate this at compile time (the call to
startActivity(Intent, Bundle)). Also what should happen if somebody calledwithOptions()butstartActivity(Intent, Bundle)is not available (just ignore the options)?Don't you have similar issues with Fragments vs. SupportFragments and you just query to see which is available and generate accordingly? So if the method is not available you don't generate support for withOptions.
We do not entirely generate the builders. We have the super class in the
API jar, and we only generate the needed constructors with Fragment
arguments at runtime. I would like to add withOptions to the superclass and
not generate it for every builder class.@dalewking So it seems if we have the support library on the classpath, we should call
ActivityCompat#startActivity, am i right? But what we should call forFragments? I did not findstartActivitymethods in the supportFragmentclass which have theoptionsparam.I think you can also use the ActivityCompat call. I looked at fragment startActivity and it delegates to the activity. It uses slightly different code, but not sure it matters.
Are you sure? We had issue #541 when we called
Activity.startActivityForResultfromFragments instead ofFragment.startActivityForResult: theonActivityResultmethod was called on theActivityinstead of theFragment. If you check outFragment.startActivityForResultit actually callsActivity.startActivityFromFragment, and not just simplyActivity.startActivity.No I am not sure. There is probably some way to do it.
As you requested the feature, can I ask you to investigate this? ☺
Unfortunately, I requested this when working at a previous company where we made heavy use of animations. At my current company I haven't been able to convince my team to use Android Annotations yet so I am currently not using AA.
I see. I will look into this myself, then.
@yDelouis do you have experience about this?
Calling
ActivityCompat.startActivityForResultwill return to theFragmentActivityinstead of theFragmentas expected. 😞I don't have any experience about these options.
OK, i investigated a little bit. It seems
ActivityCompat.startActivityForResultcompletetely ignores the optionsBundleAPI 16 and below. Also supportFragmenthas nostartActivityForResultwith theoptionsparameter. So i think we can just ignore the options ifFragment.startActivityForResult(Intent intent, int requestCode, Bundle options)is not available.@dalewking i added a PR which implements this feature. Unfortunately it is much complicated as we thought, because there are lots of cases.
Implemented.
API 16 added a new optional Bundle parameter for starting activities which is used to control animation of activity and it was also added to the support library for backwards compatibility. The generated intent builder needs to support this new way to start activities.
See http://developer.android.com/reference/android/app/ActivityOptions.html