App Lifecycle & Background Execution
AppState, foreground/background transitions, headless JS, background fetch, deep links, universal links
1What are the three possible states returned by AppState.currentState in React Native?
What are the three possible states returned by AppState.currentState in React Native?
답변
AppState.currentState returns one of three states: 'active' (app is in the foreground and interactive), 'background' (app is in the background but potentially running) and 'inactive' (transitional state on iOS, for example when displaying the multitasking view). On Android, 'inactive' state is rare as the transition goes directly between 'active' and 'background'.
2Which method should be used to listen for application state changes with AppState?
Which method should be used to listen for application state changes with AppState?
답변
The AppState.addEventListener('change', callback) method allows listening for application state changes. The callback receives the new state ('active', 'background' or 'inactive') as a parameter. It is important to remove the listener using the remove() method returned by addEventListener during cleanup to avoid memory leaks.
3When does the 'inactive' state typically occur on iOS?
When does the 'inactive' state typically occur on iOS?
답변
The 'inactive' state on iOS occurs during brief transitions: displaying the control center, notification center, multitasking screen (double tap Home), or during an incoming call. It is an intermediate state where the app is visible but not interactive. On Android, this state is rarely observed as the transition between 'active' and 'background' is direct.
How to correctly implement an AppState listener in a useEffect?
What is a Headless JS Task in React Native?
+17 면접 질문