|
15 | 15 | import com.facebook.react.bridge.Arguments;
|
16 | 16 | import com.facebook.react.bridge.Callback;
|
17 | 17 | import com.facebook.react.bridge.GuardedAsyncTask;
|
| 18 | +import com.facebook.react.bridge.LifecycleEventListener; |
18 | 19 | import com.facebook.react.bridge.ReactApplicationContext;
|
19 | 20 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
20 | 21 | import com.facebook.react.bridge.ReactMethod;
|
|
33 | 34 |
|
34 | 35 | @ReactModule(name = AsyncStorageModule.NAME)
|
35 | 36 | public final class AsyncStorageModule
|
36 |
| - extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable { |
| 37 | + extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable, LifecycleEventListener { |
37 | 38 |
|
38 | 39 | // changed name to not conflict with AsyncStorage from RN repo
|
39 | 40 | public static final String NAME = "RNC_AsyncSQLiteDBStorage";
|
@@ -91,6 +92,7 @@ public AsyncStorageModule(ReactApplicationContext reactContext) {
|
91 | 92 | AsyncStorageModule(ReactApplicationContext reactContext, Executor executor) {
|
92 | 93 | super(reactContext);
|
93 | 94 | this.executor = new SerialExecutor(executor);
|
| 95 | + reactContext.addLifecycleEventListener(this); |
94 | 96 | mReactDatabaseSupplier = ReactDatabaseSupplier.getInstance(reactContext);
|
95 | 97 | }
|
96 | 98 |
|
@@ -118,6 +120,18 @@ public void clearSensitiveData() {
|
118 | 120 | mReactDatabaseSupplier.clearAndCloseDatabase();
|
119 | 121 | }
|
120 | 122 |
|
| 123 | + @Override |
| 124 | + public void onHostResume() {} |
| 125 | + |
| 126 | + @Override |
| 127 | + public void onHostPause() {} |
| 128 | + |
| 129 | + @Override |
| 130 | + public void onHostDestroy() { |
| 131 | + // ensure we close database when activity is destroyed |
| 132 | + mReactDatabaseSupplier.closeDatabase(); |
| 133 | + } |
| 134 | + |
121 | 135 | /**
|
122 | 136 | * Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
|
123 | 137 | * (key, null) for the keys that haven't been found.
|
|
0 commit comments