Is it generally good practice not to hardcode strings used as keys in dictionaries, maps and extras bundles etc, or does it matter?
extras.putSerializable("myKey", getItem(thisIndex).getSomeObject());
verses
extras.putSerializable(ctx.getString(R.string.my_key), getItem(thisIndex).getSomeObject());
I’m doing the following when instantiating fragments and associating a page title with the fragment for use with a page title indicator
Bundle pageTitle = new Bundle();
pageTitle.putSerializable(getString(R.string.page_title_key), getString(R.string.somePageTitle));
fragments.add(Fragment.instantiate(this, MyPageFragment.class.getName(), pageTitle));
Then in my FragmentPagerAdapter:
@Override
public CharSequence getPageTitle(int position) {
return this.fragments.get(position).getArguments().getSerializable(ctx.getString(R.string.page_title_key)).toString();
}
Good programming and the MVC model would say to not hard code your key. I also would not put it in your strings resource. Instead, I prefer to use constants. If you define them as
public staticother classes will be able to reference the same data as well. That way you only need to type out the actual key once in your code.