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.
Add support for Bundle parameter when starting activity #1027
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.
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.
@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.
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 called withOptions() but startActivity(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 for Fragments? I did not find startActivity methods in the support Fragment class which have the options param.
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.startActivityForResult from Fragments instead of Fragment.startActivityForResult: the onActivityResult method was called on the Activity instead of the Fragment. If you check out Fragment.startActivityForResult it actually calls Activity.startActivityFromFragment, and not just simply Activity.startActivity.
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.
OK, i investigated a little bit. It seems ActivityCompat.startActivityForResult completetely ignores the options Bundle API 16 and below. Also support Fragment has no startActivityForResult with the options parameter. So i think we can just ignore the options if Fragment.startActivityForResult(Intent intent, int requestCode, Bundle options) is not available.
Activity
DayS commentedon Jun 8, 2014
I must be retarded :) I which support class is there support for this ?
dalewking commentedon Jun 8, 2014
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.
WonderCsabo commentedon Aug 22, 2014
I agree, we should support bundle parameters in the
start()method.WonderCsabo commentedon Dec 23, 2014
@dalewking @DayS @yDelouis do you thought abut this?
dalewking commentedon Dec 23, 2014
@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.
WonderCsabo commentedon Dec 23, 2014
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)?dalewking commentedon Dec 23, 2014
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.
WonderCsabo commentedon Dec 23, 2014
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.
WonderCsabo commentedon Dec 25, 2014
@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.dalewking commentedon Dec 26, 2014
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.
WonderCsabo commentedon Dec 26, 2014
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.dalewking commentedon Dec 26, 2014
No I am not sure. There is probably some way to do it.
WonderCsabo commentedon Dec 26, 2014
As you requested the feature, can I ask you to investigate this? ☺
dalewking commentedon Dec 26, 2014
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.
WonderCsabo commentedon Dec 26, 2014
I see. I will look into this myself, then.
WonderCsabo commentedon Dec 28, 2014
@yDelouis do you have experience about this?
WonderCsabo commentedon Dec 28, 2014
Calling
ActivityCompat.startActivityForResultwill return to theFragmentActivityinstead of theFragmentas expected. 😞yDelouis commentedon Dec 28, 2014
I don't have any experience about these options.
WonderCsabo commentedon Dec 28, 2014
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.WonderCsabo commentedon Dec 29, 2014
@dalewking i added a PR which implements this feature. Unfortunately it is much complicated as we thought, because there are lots of cases.
WonderCsabo commentedon Mar 22, 2015
Implemented.