RN push & background · Concept
Foreground, background and killed-state handling
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
A data message arrives when the app is (a) open, (b) backgrounded, (c) swiped away. What code runs in each case, and where must the background handler be registered?
// index.js
messaging().setBackgroundMessageHandler(async msg => { /* ? */ });
AppRegistry.registerComponent(appName, () => App);
Then
Follow-ups the interviewer asks next
- "Why must it be in
index.js, outside React?" - "iOS: will a data-only message wake a killed app?"
- "Android: why didn't a normal-priority message arrive in Doze?"
- "
getInitialNotificationvsonNotificationOpenedApp?"
The answer
What a strong answer covers
- Foreground:
onMessage(no system UI for data messages, so display it yourself). - Background or quit (Android): the background handler runs headless JS, so register it before
registerComponentand keep it short. - Notification payloads are shown by the OS when the app is in the background.
- iOS:
content-availablebackground pushes are throttled and not delivered after a user force-quit. - Android: Doze restricts normal-priority FCM messages, so use high priority sparingly.
- Tap handling:
getInitialNotification(cold start) vsonNotificationOpenedApp(from background).
The red pen
Common traps
Avoid:registering the handler inside a component. Expecting a guaranteed wake on iOS.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.