Source:
<code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); ArrayList<Integer> selectedItems = new ArrayList<>(); mIsSelectOneItem = getIntent().getBooleanExtra(PARAM_SELECT_ONE_ITEM, false); ArrayList<Integer> prevSelectedItems = ListUtils.fromIntArray(getIntent().getIntArrayExtra(PARAM_SELECTED_IDS)); if (prevSelectedItems != null) { selectedItems.addAll(prevSelectedItems); } if (savedInstanceState != null) { mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); mIsSelectOneItem = savedInstanceState.getBoolean(STATE_IS_SELECT_ONE_ITEM, mIsSelectOneItem); if (savedInstanceState.containsKey(STATE_SELECTED_ITEMS)) { ArrayList<Integer> list = ListUtils.fromIntArray(savedInstanceState.getIntArray(STATE_SELECTED_ITEMS)); selectedItems.addAll(list); } if (savedInstanceState.containsKey(STATE_FILTERED_ITEMS)) { mFilteredItems = ListUtils.fromLongArray(savedInstanceState.getLongArray(STATE_FILTERED_ITEMS)); } } else { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); } if (mSite == null) { ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT); finish(); return; } setContentView(R.layout.media_gallery_picker_layout); mRecycler = (RecyclerView) findViewById(R.id.recycler); int numColumns = MediaGridAdapter.getColumnCount(this); mGridManager = new GridLayoutManager(this, numColumns); mRecycler.setLayoutManager(mGridManager); mGridAdapter = new MediaGridAdapter(this, mSite, WordPress.sImageLoader); <START> mGridAdapter.setCallback(this); <END> mRecycler.setAdapter(mGridAdapter); if (mIsSelectOneItem) { mGridAdapter.setAllowMultiselect(false); setTitle(R.string.select_from_media_library); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } } else { mGridAdapter.setAllowMultiselect(true); mGridAdapter.setInMultiSelect(true); mGridAdapter.setSelectedItems(selectedItems); } }</code><technical_language>Awesome, thank Nick</technical_language>

Target:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); ArrayList<Integer> selectedItems = new ArrayList<>(); mIsSelectOneItem = getIntent().getBooleanExtra(PARAM_SELECT_ONE_ITEM, false); ArrayList<Integer> prevSelectedItems = ListUtils.fromIntArray(getIntent().getIntArrayExtra(PARAM_SELECTED_IDS)); if (prevSelectedItems != null) { selectedItems.addAll(prevSelectedItems); } if (savedInstanceState != null) { mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); mIsSelectOneItem = savedInstanceState.getBoolean(STATE_IS_SELECT_ONE_ITEM, mIsSelectOneItem); if (savedInstanceState.containsKey(STATE_SELECTED_ITEMS)) { ArrayList<Integer> list = ListUtils.fromIntArray(savedInstanceState.getIntArray(STATE_SELECTED_ITEMS)); selectedItems.addAll(list); } if (savedInstanceState.containsKey(STATE_FILTERED_ITEMS)) { mFilteredItems = ListUtils.fromLongArray(savedInstanceState.getLongArray(STATE_FILTERED_ITEMS)); } } else { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); } if (mSite == null) { ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT); finish(); return; } setContentView(R.layout.media_gallery_picker_layout); mRecycler = (RecyclerView) findViewById(R.id.recycler); int numColumns = MediaGridAdapter.getColumnCount(this); mGridManager = new GridLayoutManager(this, numColumns); mRecycler.setLayoutManager(mGridManager); mGridAdapter = new MediaGridAdapter(this, mSite, mImageLoader); mGridAdapter.setCallback(this); mRecycler.setAdapter(mGridAdapter); if (mIsSelectOneItem) { mGridAdapter.setAllowMultiselect(false); setTitle(R.string.select_from_media_library); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } } else { mGridAdapter.setAllowMultiselect(true); mGridAdapter.setInMultiSelect(true); mGridAdapter.setSelectedItems(selectedItems); } }