6
6
import com .facebook .react .bridge .Callback ;
7
7
import com .facebook .react .bridge .LifecycleEventListener ;
8
8
import com .facebook .react .bridge .ReactApplicationContext ;
9
+ import com .facebook .react .bridge .ReactContext ;
9
10
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
10
11
import com .facebook .react .bridge .ReactMethod ;
11
12
import com .facebook .react .bridge .ReadableMap ;
@@ -47,7 +48,7 @@ public class BackgroundGeolocationModule extends ReactContextBaseJavaModule impl
47
48
48
49
private BackgroundGeolocationFacade facade ;
49
50
private org .slf4j .Logger logger ;
50
- private ReactApplicationContext currentContext ;
51
+ private ReactContext currentContext ;
51
52
52
53
public static class ErrorMap {
53
54
public static ReadableMap from (String message , int code ) {
@@ -85,10 +86,10 @@ private static WritableMap from(Throwable e) {
85
86
86
87
public BackgroundGeolocationModule (ReactApplicationContext reactContext ) {
87
88
super (reactContext );
88
- reactContext .addLifecycleEventListener (this );
89
89
currentContext = reactContext ;
90
+ currentContext .addLifecycleEventListener (this );
90
91
91
- facade = new BackgroundGeolocationFacade (getContext () , this );
92
+ facade = new BackgroundGeolocationFacade (currentContext , this );
92
93
logger = LoggerManager .getLogger (BackgroundGeolocationModule .class );
93
94
}
94
95
@@ -129,6 +130,13 @@ public void onHostDestroy() {
129
130
// facade = null;
130
131
}
131
132
133
+ @ Override
134
+ public void onCatalystInstanceDestroy () {
135
+ super .onCatalystInstanceDestroy ();
136
+ logger .info ("Destroying plugin facade" );
137
+ facade .destroy ();
138
+ }
139
+
132
140
private void runOnBackgroundThread (Runnable runnable ) {
133
141
// currently react-native has no other thread we can run on
134
142
new Thread (runnable ).start ();
@@ -325,9 +333,14 @@ public void forceSync(Callback success, Callback error) {
325
333
}
326
334
327
335
private void sendEvent (String eventName , Object params ) {
328
- currentContext
329
- .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
330
- .emit (eventName , params );
336
+ try {
337
+ currentContext .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
338
+ .emit (eventName , params );
339
+ }
340
+ catch (Exception e ){
341
+ logger .debug ("error sending event: {}" , e .toString ());
342
+ }
343
+
331
344
}
332
345
333
346
private void sendError (PluginException error ) {
@@ -350,7 +363,7 @@ public int getAuthorizationStatus() {
350
363
return facade .getAuthorizationStatus ();
351
364
}
352
365
353
- public Context getContext () {
366
+ public ReactContext getContext () {
354
367
// return getReactApplicationContext().getBaseContext();
355
368
return currentContext ;
356
369
}
0 commit comments