react-native-activity-android
Provides a method to move Android apps to the background (instead of exiting), and lifecycle hooks when the application is paused and resumed.
Useful if you want to capture listen for BackButton
press and pause your application.
Installation
-
Install module
npm install --save react-native-activity-android
-
In
android/setting.gradle
... include ':ActivityAndroid', ':app' project(':ActivityAndroid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-activity-android/android')
-
In
android/app/build.gradle
... dependencies { ... compile project(':ActivityAndroid') }
-
Register module (in
MainActivity.java
)import ca.jaysoo.activityandroid.ActivityAndroidPackage; // <---- Import here public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { ...... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) .addPackage(new ActivityAndroidPackage(this)) // <---- Add here .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null); setContentView(mReactRootView); } ...... }
Usage
Moving an application to the background.
;; BackAndroid;
Lifecycle hooks.
; ActivityAndroid; ActivityAndroid; ActivityAndroid;ActivityAndroid);