react-native-android-lifecycle
v1.3.0
Published
hock android lifecycle on react-native
Downloads
2
Readme
react-native-android-lifecycle
Getting started
$ npm install react-native-android-lifecycle --save
Mostly automatic installation
$ react-native link react-native-android-lifecycle
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNAndroidLifecyclePackage;
to the imports at the top of the file - Add
new RNAndroidLifecyclePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-android-lifecycle' project(':react-native-android-lifecycle').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-lifecycle/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-android-lifecycle')
Usage
import RNAndroidLifeCycle from 'react-native-android-lifecycle';
RNAndroidLifeCycle.on(RNAndroidLifeCycle.event.ON_NEW_INTENT, () => {
console.log("ON_NEW_INTENT");
});
RNAndroidLifeCycle.on(RNAndroidLifeCycle.event.ON_ACTIVITY_RESULT, (e) => {
console.log("ON_ACTIVITY_RESULT", e);
});
RNAndroidLifeCycle.on(RNAndroidLifeCycle.event.ON_HOST_RESUME, () => {
console.log("ON_HOST_RESUME");
});
RNAndroidLifeCycle.on(RNAndroidLifeCycle.event.ON_HOST_PAUSE, () => {
console.log("ON_HOST_PAUSE");
});
RNAndroidLifeCycle.on(RNAndroidLifeCycle.event.ON_HOST_DESTROY, () => {
console.log("ON_HOST_DESTROY");
});