mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-01-12 22:50:20 +08:00
[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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user