react native event when first opened - react-native

I am trying to get the correct event for the first start up in a react native app.
I understand AppState and can get these statuses from the React Native Docs
App States
active - The app is running in the foreground
background - The app is running in the background. The user is either
in another app or on the home screen
inactive - This is a state that occurs when transitioning between
foreground & background, and during periods of inactivity such as
entering the Multitasking view or in the event of an incoming call
In the docs it mentions that when the app first loads AppState.currentState will be null, but I can find when that would happen.
Why do I even care you ask, I am trying to send a "login" event, but I don't want it every time the app becomes active. If it is relevant I am working on a cross platform app, both Android and IOS need to be supported.

Related

How to schedule periodic local notifications with dynamic content in React Native using Expo?

I am building a React Native app and would like to add weekly local notifications. The notifications should include dynamic data, such as a screen time increase, which will be calculated right before the notification is sent.
When the user enables the notifications by clicking "Enable Weekly Reports", the scheduleNotificationAsync method is called, taking the title parameter as input. However, the title will change over time.
What is the best way to periodically schedule notifications with dynamic content in React Native using the expo-notifications API?
Note: The BackgroundFetch method only works when the app is in the background, not if the app has been terminated or after a device reboot.
Related Questions:
React Native - Expo notification Scheduling

Is there an event to listen on for when a React Native app is quit?

Im interested in firing a function when a user quits the app, meaning they bring up multi-tasking and close-out the app.
I'm not talking about navigating back to your home screen and keeping the app in the background.
I'm aware of AppState, but as I said, im looking for the suit scenario, not a change from active, to the background
Is this possible, my componentWillUnmount() is not firing in this case?
Here is an example using an OS background task and additional library. That might be your best bet without using AppState/ComponentDidUnmount() which would only detect active/background status:
https://github.com/billmalarky/react-native-queue#os-background-task-full-example
componentWillUnmount() won't fire because that's only when a component is being removed from the DOM.
The JavaScript engine closes when the app does so there's no other way to communicate with it once the app is closed.

Expo - scheduled notification. Bring app to foreground

I have been searching through the Expo documentation and haven't been able to find anything.
Is it possible to bring an app to the foreground using expo?
e.g. if I made a simple alarm clock - would it be possible to bring the app to the foreground and show an alarm screen without actively clicking on a notification?
I'm interested in both iOS and Android - any information is very much appreciated.

need the react native app to receive headset button event when the device is in locked state

How to run react native app in background. I need the app to accept the voice command when i click the headset button even when the device is in locked state.
Basically headset button click event should trigger the app to listen for voice. Currently my app accepting the voice command in foreground mode and works. but my requirement is even if device is locked , up on clicking the head set button i should trigger the app.
It wasn't done before but today you can by adding some libraries to create a background service. I believe you can later capture the event you want. this what you will tell us.
Follow this link to learn how to create the background service
Libraries you will need:
React Native Queue
react-native-background-task

React-Native: How to get Screen Lock time?

I need to find whether the application sent in background manually or automatically? In react-native, if the screen gets locked, the app state treats it as background. It doesn't matters if you intentionally send the app to background(by either killing the app or pressing home button) or it was sent in the background automatically(due to screen lock). Is it possible to distinguish both events? Is there any way in react-native to find out the device's screen lock time?
After a long search I found this:
https://www.npmjs.com/package/react-native-home-pressed