是不是硬編碼在字典,地圖和演員包等中用作鍵的字符串是好的做法,還是這很重要?我應該將存儲在Android Bundles中的字符串用作資源嗎?
extras.putSerializable("myKey", getItem(thisIndex).getSomeObject());
經文
extras.putSerializable(ctx.getString(R.string.my_key), getItem(thisIndex).getSomeObject());
我做實例片段,並在我的FragmentPagerAdapter用於與網頁標題指標使用
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));
然後與相關聯的片段的頁面標題時,以下:
@Override
public CharSequence getPageTitle(int position) {
return this.fragments.get(position).getArguments().getSerializable(ctx.getString(R.string.page_title_key)).toString();
}