@Override public void onDestroy() { super.onDestroy(); if (getReactNativeHost().hasInstance()) { ReactInstanceManager reactInstanceManager = getReactNativeHost().getReactInstanceManager(); ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); if (reactContext != null) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); headlessJsTaskContext.removeTaskEventListener(this); } } if (sWakeLock != null) { sWakeLock.release(); } }
@ReactMethod public void notifyTaskFinished(int taskId) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); if (headlessJsTaskContext.isTaskRunning(taskId)) { headlessJsTaskContext.finishTask(taskId); } else { FLog.w( HeadlessJsTaskSupportModule.class, "Tried to finish non-active task with id %d. Did it time out?", taskId); } }
@Override public void initialize() { getReactApplicationContext().addLifecycleEventListener(this); HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); headlessJsTaskContext.addTaskEventListener(this); }
@Override public void onHeadlessJsTaskFinish(int taskId) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); if (!headlessJsTaskContext.hasActiveTasks()) { isRunningTasks.set(false); clearFrameCallback(); maybeIdleCallback(); } }
@Override public void onCatalystInstanceDestroy() { clearFrameCallback(); clearChoreographerIdleCallback(); HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); headlessJsTaskContext.removeTaskEventListener(this); }
private void clearFrameCallback() { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); if (mFrameCallbackPosted && isPaused.get() && !headlessJsTaskContext.hasActiveTasks()) { Assertions.assertNotNull(mReactChoreographer).removeFrameCallback( ReactChoreographer.CallbackType.TIMERS_EVENTS, mTimerFrameCallback); mFrameCallbackPosted = false; } }
@Override public void initialize() { // Safe to acquire choreographer here, as initialize() is invoked from UI thread. mReactChoreographer = ReactChoreographer.getInstance(); getReactApplicationContext().addLifecycleEventListener(this); HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); headlessJsTaskContext.addTaskEventListener(this); }
@Override public void onHeadlessJsTaskFinish(int taskId) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); if (!headlessJsTaskContext.hasActiveTasks()) { isRunningTasks.set(false); clearChoreographerCallback(); maybeClearChoreographerIdleCallback(); } }
@Override public void onCatalystInstanceDestroy() { clearChoreographerCallback(); clearChoreographerIdleCallback(); HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); headlessJsTaskContext.removeTaskEventListener(this); }
private void clearChoreographerCallback() { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); if (mFrameCallbackPosted && isPaused.get() && !headlessJsTaskContext.hasActiveTasks()) { Assertions.assertNotNull(mReactChoreographer).removeFrameCallback( ReactChoreographer.CallbackType.TIMERS_EVENTS, mTimerFrameCallback); mFrameCallbackPosted = false; } }
private void invokeStartTask(ReactContext reactContext, HeadlessJsTaskConfig taskConfig) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); headlessJsTaskContext.addTaskEventListener(this); int taskId = headlessJsTaskContext.startTask(taskConfig); mActiveTasks.add(taskId); }
@ReactMethod public void notifyTaskFinished(int taskId) { HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()); headlessJsTaskContext.finishTask(taskId); }
private void invokeStartTask(ReactContext reactContext, final HeadlessJsTaskConfig taskConfig) { final HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext); headlessJsTaskContext.addTaskEventListener(this); mActiveTaskContext = headlessJsTaskContext; UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { int taskId = headlessJsTaskContext.startTask(taskConfig); } }); }