Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
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

Description

@dalewking

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

Activity

  1. DayS commented on Jun 8, 2014

    @DayS
    Contributor

    I must be retarded :) I which support class is there support for this ?

  2. dalewking commented on Jun 8, 2014

    @dalewking
    Author

    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.

  3. WonderCsabo commented on Aug 22, 2014

    @WonderCsabo
    Member

    I agree, we should support bundle parameters in the start() method.

  4. WonderCsabo commented on Dec 23, 2014

    @WonderCsabo
    Member

    @dalewking @DayS @yDelouis do you thought abut this?

    MyActivity_.intent(this).bundle(options).start();
  5. dalewking commented on Dec 23, 2014

    @dalewking
    Author

    @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.

  6. WonderCsabo commented on Dec 23, 2014

    @WonderCsabo
    Member

    OK, withOptions is 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 called withOptions() but startActivity(Intent, Bundle) is not available (just ignore the options)?

  7. dalewking commented on Dec 23, 2014

    @dalewking
    Author

    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.

  8. WonderCsabo commented on Dec 23, 2014

    @WonderCsabo
    Member

    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.

  9. WonderCsabo commented on Dec 25, 2014

    @WonderCsabo
    Member

    @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.

  10. dalewking commented on Dec 26, 2014

    @dalewking
    Author

    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.

  11. WonderCsabo commented on Dec 26, 2014

    @WonderCsabo
    Member

    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.

  12. dalewking commented on Dec 26, 2014

    @dalewking
    Author

    No I am not sure. There is probably some way to do it.

  13. WonderCsabo commented on Dec 26, 2014

    @WonderCsabo
    Member

    As you requested the feature, can I ask you to investigate this? ☺

  14. dalewking commented on Dec 26, 2014

    @dalewking
    Author

    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.

  15. WonderCsabo commented on Dec 26, 2014

    @WonderCsabo
    Member

    I see. I will look into this myself, then.

  16. WonderCsabo commented on Dec 28, 2014

    @WonderCsabo
    Member

    @yDelouis do you have experience about this?

  17. WonderCsabo commented on Dec 28, 2014

    @WonderCsabo
    Member

    Calling ActivityCompat.startActivityForResult will return to the FragmentActivity instead of the Fragment as expected. 😞

  18. yDelouis commented on Dec 28, 2014

    @yDelouis
    Contributor

    I don't have any experience about these options.

  19. WonderCsabo commented on Dec 28, 2014

    @WonderCsabo
    Member

    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.

  20. self-assigned this
    on Dec 28, 2014
  21. WonderCsabo commented on Dec 29, 2014

    @WonderCsabo
    Member

    @dalewking i added a PR which implements this feature. Unfortunately it is much complicated as we thought, because there are lots of cases.

  22. WonderCsabo commented on Mar 22, 2015

    @WonderCsabo
    Member

    Implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions