I have a setInterval that keeps running even when you close (not quit) the app. I would like to call a function when my app is closed or the device is put to sleep so that it clears the setInterval.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
itinance was close. The answer is actually to use
AppState is your friend! Have a look at the documentation of AppState.
So in your component, where the setTimeout exists, just require AppState and add an event listener like this:
handlePutAppToBackground() would be now a method in your component, where you would call clearTimeout(...)