Skip to content

Commit 99b33b7

Browse files
authored
fix: use proper context instead of activity (#1232)
1 parent 1814f4a commit 99b33b7

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

android/src/main/java/com/bleplx/BlePlxModule.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.bleplx;
22

3-
import android.app.Activity;
4-
53
import androidx.annotation.NonNull;
64
import androidx.annotation.Nullable;
75

@@ -52,9 +50,11 @@
5250
@ReactModule(name = BlePlxModule.NAME)
5351
public class BlePlxModule extends ReactContextBaseJavaModule {
5452
public static final String NAME = "BlePlx";
53+
private final ReactApplicationContext reactContext;
5554

5655
public BlePlxModule(ReactApplicationContext reactContext) {
5756
super(reactContext);
57+
this.reactContext = reactContext;
5858
RxJavaPlugins.setErrorHandler(throwable -> {
5959
if (throwable instanceof UndeliverableException) {
6060
RxBleLog.e("Handle all unhandled exceptions from RxJava: " + throwable.getMessage());
@@ -98,11 +98,7 @@ public Map<String, Object> getConstants() {
9898

9999
@ReactMethod
100100
public void createClient(String restoreStateIdentifier) {
101-
final Activity activity = getCurrentActivity();
102-
if (activity == null) {
103-
return;
104-
}
105-
bleAdapter = BleAdapterFactory.getNewAdapter(activity);
101+
bleAdapter = BleAdapterFactory.getNewAdapter(reactContext);
106102
bleAdapter.createClient(restoreStateIdentifier,
107103
new OnEventCallback<String>() {
108104
@Override

0 commit comments

Comments
 (0)