title: React Native ReactContext lifecycle stuck on BEFORE_CREATE
body: <p>I'm trying to run a background service in React-Native. From what I've heard I need to write it in native Java and connect it to the react-native code. When I try to emit an event I get an error:</p>
  
  <pre><code>Tried to access a JS module before the React instance was fully set up. Calls to should only happen once initialize() has been called on your native module.
  </code></pre>
  
  <p>So I added a check to see if the Module is running:</p>
  
  <pre><code>if (reactContext.getLifecycleState() == LifecycleState.RESUMED)
  </code></pre>
  
  <p>But it always returns false. The lifecycle is stuck on BEFORE_CREATE. How should I emit my event.</p>
  
  <p>Service:</p>
  
  <pre><code>public class TestService extends Service {
  
  double distance = 0.0;
  ReactContext reactContext;
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      reactContext = new ReactContext(getApplicationContext());
      new Timer().scheduleAtFixedRate(new TimerTask(){
          @Override
          public void run(){
              WritableMap params = Arguments.createMap();
              distance+= 0.7;
              Log.d("LOG", "Trying to send distance: "+distance+" on lifecycle: "+reactContext.getLifecycleState());
              params.putDouble("distance", distance);
              sendEvent(reactContext, "updateDistance", params);
          }
      },0,1000);
      return START_STICKY;
  }
  
  private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
      if (reactContext.getLifecycleState() == LifecycleState.RESUMED) {
          reactContext.getJSModule(DeviceEventManagerModule
                  .RCTDeviceEventEmitter.class)
                  .emit(eventName, params);
          Log.d("LOG", "Sent distance: "+distance);
      }
  }
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  }
  </code></pre>
  
  <p>Module:</p>
  
  <pre><code>public class ServiceModule extends ReactContextBaseJavaModule {
  ReactContext reactContext;
  
  public ServiceModule(ReactApplicationContext reactContext) {
      super(reactContext);
      this.reactContext = reactContext;
      this.initialize();
  }
  
  @ReactMethod
  public void startTrackingService() {
      Intent intent = new Intent(reactContext, TestService.class);
      reactContext.startService(intent);
  }
  
  @Override
  public String getName() {
      return "ServiceModule";
  }
  }
  </code></pre>
  
  <p>Package:</p>
  
  <pre><code>public class ServicePackage implements ReactPackage {
  @Override
  public List&lt;NativeModule&gt; createNativeModules(ReactApplicationContext reactContext) {
      List&lt;NativeModule&gt; modules = new ArrayList&lt;&gt;();
      modules.add(new ServiceModule(reactContext));
      return modules;
  }
  
  @Override
  public List&lt;Class&lt;? extends JavaScriptModule&gt;&gt; createJSModules() {
      return Collections.emptyList();
  }
  
  @Override
  public List&lt;ViewManager&gt; createViewManagers(ReactApplicationContext reactContext) {
      return Collections.emptyList();
  }
  }
  </code></pre>
  
  <p>MainApplication:</p>
  
  <pre><code>@Override
  protected List&lt;ReactPackage&gt; getPackages() {
    return Arrays.&lt;ReactPackage&gt;asList(
        new MainReactPackage(),
        new ReactNativePushNotificationPackage(),
        new ServicePackage()
    );
  }
  </code></pre>