I was seeing the code of backhandler in react native. I understand that they are pushing the handler in _backPressSubscriptions. But after if condition they are removing it using removeEventListener in the return.
addEventListener: function (
eventName: BackPressEventName,
handler: () => ?boolean,
): {remove: () => void, ...} {
if (_backPressSubscriptions.indexOf(handler) === -1) {
_backPressSubscriptions.push(handler);
}
return {
remove: (): void => BackHandler.removeEventListener(eventName, handler),
};
},
Full code: https://github.com/facebook/react-native/blob/main/Libraries/Utilities/BackHandler.android.js
Also will BackHandler work on emulator?