How to execute function while the phone is locked?

Viewed 153

I am working on mobile application that needs to logout the user after some time of inactivity, using React-native. Firstly I tried to use react-native-user-inactivity, but I faced some troubles on Android and I decided to write custom logic for it. I use timer and pan responder to detect user gestures and tapings. When the user taps, the timer is reset. This is working fine when the app is on foreground. I want to logout the user even when the phone is locked. How can I execute function when the screen is locked?

1 Answers

Your best bet would be to react to set some sort of time flag for when the app went to the background, then check the timeout when the app comes back to the foreground.

Likely using the componentDidMount and componentWillUnmount life cycle methods.

Related