Skip to content

Commit 913daa8

Browse files
committed
Compatible with #863 (v27.1.0+)
1 parent 7c0fdea commit 913daa8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ ext {
2828
minSdkVersion = 14
2929
targetSdkVersion = compileSdkVersion
3030

31-
v4Version = "27.1.0"
31+
v4Version = "27.1.1"
3232
}

fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
*/
1616
public class FragmentationMagician {
1717
public static boolean sSupportLessThan25dot4 = false;
18+
public static boolean sSupportGreaterThan27dot1dot0 = false;
1819

1920
static {
2021
Field[] fields = FragmentManagerImpl.class.getDeclaredFields();
2122
for (Field field : fields) {
22-
if (field.getName().equals("mAvailIndices")) {
23+
if (field.getName().equals("mStopped")) { // > v27.1.0
24+
sSupportGreaterThan27dot1dot0 = true;
25+
break;
26+
} else if (field.getName().equals("mAvailIndices")) { // < 25.4.0
2327
sSupportLessThan25dot4 = true;
2428
break;
2529
}
@@ -180,10 +184,27 @@ private static void hookStateSaved(FragmentManager fragmentManager, Runnable run
180184
FragmentManagerImpl fragmentManagerImpl = (FragmentManagerImpl) fragmentManager;
181185
if (isStateSaved(fragmentManager)) {
182186
fragmentManagerImpl.mStateSaved = false;
183-
runnable.run();
187+
compatRunAction(fragmentManagerImpl, runnable);
184188
fragmentManagerImpl.mStateSaved = true;
185189
} else {
186190
runnable.run();
187191
}
188192
}
193+
194+
/**
195+
* Compat v27.1.0+
196+
*
197+
* So the code to compile Fragmentation needs v27.1.0+
198+
*
199+
* @see FragmentManager#isStateSaved()
200+
*/
201+
private static void compatRunAction(FragmentManagerImpl fragmentManagerImpl, Runnable runnable) {
202+
if (sSupportGreaterThan27dot1dot0) {
203+
fragmentManagerImpl.mStopped = false;
204+
runnable.run();
205+
fragmentManagerImpl.mStopped = true;
206+
} else {
207+
runnable.run();
208+
}
209+
}
189210
}

0 commit comments

Comments
 (0)