Skip to content

Commit c0581af

Browse files
JakeWhartonDianne Hackborn
authored andcommitted
DO NOT MERGE. Do not dispatch context selection events to non-visible fragments.
When used in a `ViewPager`, fragments that are present on the adjacent, cached pages will receive context selection dispatches which, depending on your fragment contents, can be difficult to determine whether or not the event truly originated from your view. By using the visible hint we restrict dispatching to only those fragments which are marked as being visible. Since the fragment pager adapter updates this setting properly most implementations will be afforded this fix without any change required. If the user is implementing their own adapter they likely already understand the implications of these cached fragments and the reponsibility for updating the boolean falls to them. Mirrors support library change Ie6a72c1c82c2784774373670007b6f5948fe16da Integrated from AOSP. Change-Id: I19bbbe4c8d910fb38c14d6ae5d462eb7dd44fd26
1 parent 1b8f499 commit c0581af

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/java/android/app/FragmentManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ public boolean dispatchContextItemSelected(MenuItem item) {
18901890
if (mActive != null) {
18911891
for (int i=0; i<mAdded.size(); i++) {
18921892
Fragment f = mAdded.get(i);
1893-
if (f != null && !f.mHidden) {
1893+
if (f != null && !f.mHidden && f.mUserVisibleHint) {
18941894
if (f.onContextItemSelected(item)) {
18951895
return true;
18961896
}

0 commit comments

Comments
 (0)