Storage of extra keys



  • In my project, I have a need to transfer some data to fragment. I did it with bundle. The intent includes certain values that determine the behaviour of the fragment. It looks like,

    Fragment fragment = SomeFragment()
    Bundle bundle = Bundle()
    bundle.putString(key, value)
    fragment.arguments = bundle
    

    SomeFragment is inspected for value and, depending on whether it passes or does not, the necessary behaviour is fragmented. It works, but a few things don't give me peace:

    1. Where do you keep the key to not copy it with your hands? If common solutions are to do so.
    2. Should we combine two very similar behaviors in one fragment? (A good example will be the display of the list / the display of the selected list)


  • (1) Maybe I didn't quite understand the question. Correct if you're wrong. It's common to use a class with constants:

    public class BunldeConstants{
       public static final String MY_KEY = "super_key";
    }
    

    And use it later:

    Fragment fragment = SomeFragment();
    Bundle bundle = Bundle();
    bundle.putString(BunldeConstants.MY_KEY, value);
    

    (2) Personally, I try to use the code to the maximum. If you have a list on something like that. ListView It looks like there's a way to ask. Filter♪ I'd like to offer a condition for this filter with help. Bundle




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2