public void SetContext(ReactContext _reactContext) { lock (_lifecycleStateLock) { if (_currentReactContext != _reactContext) { if (_currentReactContext != null) { // Suspend old context if needed. We don't touch the current lifecycle state. if (_lifecycleState == LifecycleState.Foreground || _lifecycleState == LifecycleState.Background) { if (_lifecycleState == LifecycleState.Foreground) { _currentReactContext.OnEnteredBackground(); } _currentReactContext.OnSuspend(); } } _currentReactContext = _reactContext; if (_currentReactContext != null) { // Bring new context in sync with current lifecycle state if (_lifecycleState == LifecycleState.Foreground || _lifecycleState == LifecycleState.Background) { _currentReactContext.OnResume(); if (_lifecycleState == LifecycleState.Foreground) { _currentReactContext.OnLeavingBackground(); } } } } } }