Detect exiting app

Please provide the following:

  1. SDK Version: 34
  2. Platforms(Android/iOS/web/all): Android/iOS

Hi, is it possible to detect an exiting app, and run a clean up code before exiting?

Exiting means, killing the app or swiping current running apps.

I’m using managed workflow on our app.

There’s no way to detect the process actually getting killed without ejecting. You can detect when you app is being backgrounded with AppState (AppState - Expo Documentation). I’d very much recommend you do anything you need to do when you app is going to inactive status. If I had to guess as to why this isn’t available in stock RN, it’d be because I don’t think there’s an equivalent in Android to iOS’s applicationWillTerminate. So, while iOS gives you 5 seconds or so to clean up, Android doesn’t, so cleanup code on terminate that would work on iOS might not work on Android. On the other hand, in my experience, Android gives you plenty of time when the app goes inactive.

2 Likes

Hi , so if we eject, we just need to write a native module for the clean up code right?

You would need to somehow signal back to your JavaScript when AppDelegate:applicationWillTerminate: is called. Maybe EventEmitter would help? I’m not aware of an Android equivalent.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.