Shut down app on back button

I cannot shut down the app I develop and deploy with Expo. I want my app to shut down on back button, or at least on home button, but it just goes to background. (This is maybe a react-native issue)

BackHandler.exitApp() does the same thing.

How to shut down the app and not just put it to background?

https://stackoverflow.com/questions/45191413/react-native-application-does-not-shut-down-on-back-button?noredirect=1#comment77350678_45191413

I think you’ll need to eject and use a module like this one if you want this behavior.

https://github.com/wumke/react-native-exit-app

Just FYI - my understanding is that Apple and Google in general don’t advise that you explicitly kill apps. If it’s to save battery, you might want to just shutdown the parts of your app that are doing background stuff.

You can make a feature request for this to be added to expo at https://expo.canny.io/

1 Like

Thanks. Yes, I was affraid I’ll have to eject, as I havent done that ever.

I heard about not shutting them down explicitly. So you think they prefer to have apps running in the background and not to shut them down ever?

In the past I’ve gotten guidance from google that yes, the user shouldn’t think about “quitting” the way they do with a desktop app.

Also note that the OS (on either platform) might kill your app at almost any time if it’s in the background if the system needs the resources it’s taking.

1 Like

Cool. Than on app going to background I need to restart what is needed to get on the initial state, so when the user reopens it has the app as it oppened it first time.

Yeah I think that’s prob the right way to build your app.