BackHandler
The Backhandler API detects hardware button presses for back navigation, lets you register event listeners for the system's back action, and lets you control how your application responds. It is Android and Vega-only.
The event subscriptions are called in reverse order (i.e. the last registered subscription is called first).
- If one subscription returns true, then subscriptions registered earlier will not be called.
- If no subscription returns true or none are registered, it programmatically invokes the default back button functionality to exit the app.
Modal, BackHandler will not publish any events (see Modal docs).Pattern
const subscription = BackHandler.addEventListener(
'hardwareBackPress',
function () {
/**
* this.onMainScreen and this.goBack are just examples,
* you need to use your own implementation here.
*
* Typically you would use the navigator here to go to the last state.
*/
if (!this.onMainScreen()) {
this.goBack();
/**
* When true is returned the event will not be bubbled up
* & no other back action will execute
*/
return true;
}
/**
* Returning false will let the event to bubble up & let other event listeners
* or the system's default back action to be executed.
*/
return false;
},
);
// Unsubscribe the listener on unmount
subscription.remove();
Example
The following example implements a scenario where you confirm if the user wants to exit the app:
import React, {useEffect} from 'react';
import {Text, StyleSheet, BackHandler, Alert} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
useEffect(() => {
const backAction = () => {
Alert.alert('Hold on!', 'Are you sure you want to go back?', [
{
text: 'Cancel',
onPress: () => null,
style: 'cancel',
},
{text: 'YES', onPress: () => BackHandler.exitApp()},
]);
return true;
};
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
backAction,
);
return () => backHandler.remove();
}, []);
return (
<SafeAreaProvider>
<SafeAreaView style={styles.container}>
<Text style={styles.text}>Click Back button!</Text>
</SafeAreaView>
</SafeAreaProvider>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 18,
fontWeight: 'bold',
},
});
export default App;
BackHandler.addEventListener creates an event listener & returns a NativeEventSubscription object which should be cleared using NativeEventSubscription.remove method.
Usage with React Navigation
If you are using React Navigation to navigate across different screens, you can follow their guide on Custom Android back button behaviour
Backhandler hook
React Native Hooks has a nice useBackHandler hook which will simplify the process of setting up event listeners.
Reference
Methods
addEventListener()
static addEventListener(
eventName: BackPressEventName,
handler: () => boolean | null | undefined,
): NativeEventSubscription;
exitApp()
static exitApp();
For default back button functionality in case of multiple interactive components, only the interactive component will be terminated, not the entire React Native for Vega Application process. If your interactive component is a singleton or there is only one interactive component instance active for your React Native for Vega Application process, then calling exitApp will terminate the entire React Native for Vega Application process since there are no other interactive components left.
Last updated: May 13, 2026

