[android] Utils.isAppInForeground not accounting for RN LifecycleState

Prior to this change, this utility in some rare cases would return true that Activity was in the foreground, however, React Native was still in the process of resuming, this, for example, led to crashes in HeadlessJS Notification tasks: "Tried to start task RNFirebaseBackgroundMessage while in foreground, but this is not allowed."
This commit is contained in:
Michael Diarmid
2018-09-14 21:48:49 +01:00
committed by GitHub
parent 58d76d370f
commit 8a5aaa30b0

View File

@@ -9,6 +9,7 @@ import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.util.List;
@@ -151,7 +152,8 @@ public class Utils {
appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)
) {
return true;
ReactContext reactContext = (ReactContext) context;
return reactContext.getLifecycleState() == LifecycleState.RESUMED;
}
}