Shut down app on back button


#1

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


#2

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

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/


#3

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?


#4

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.


#5

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.


#6

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