React Native

App Lifecycle & Background Execution

AppState, foreground/background transitions, headless JS, background fetch, deep links, universal links

20 Interview-Fragen·
Mid-Level
1

What are the three possible states returned by AppState.currentState in React Native?

Antwort

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'.

2

Which method should be used to listen for application state changes with AppState?

Antwort

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.

3

When does the 'inactive' state typically occur on iOS?

Antwort

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.

4

How to correctly implement an AppState listener in a useEffect?

5

What is a Headless JS Task in React Native?

+17 Interview-Fragen

Meistere React Native für dein nächstes Interview

Zugang zu allen Fragen, Flashcards, technischen Tests, Code-Review-Übungen und Interview-Simulatoren.

Kostenlos starten