Skip to content

Commit

Permalink
Merge pull request #380 from luisfelipeas5/fix/use-method-channel-aft…
Browse files Browse the repository at this point in the history
…er-on-destroy

fix: stop using methodChannel after onDestroy (NullPointerException on BackgroundService.java:237)
  • Loading branch information
ekasetiawans authored Nov 18, 2023
2 parents 674cbc3 + cd0d098 commit 0703733
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public void onDestroy() {
backgroundEngine = null;
}

FlutterBackgroundServicePlugin.servicePipe.removeListener(listener);
methodChannel = null;
dartEntrypoint = null;
FlutterBackgroundServicePlugin.servicePipe.removeListener(listener);
super.onDestroy();
}

Expand Down Expand Up @@ -235,18 +235,15 @@ private void runService() {
}

public void receiveData(JSONObject data) {
if (methodChannel != null) {
try {
final JSONObject arg = data;
mainHandler.post(new Runnable() {
@Override
public void run() {
methodChannel.invokeMethod("onReceiveData", arg);
}
});
} catch (Exception e) {
e.printStackTrace();
}
if (methodChannel == null) return;
try {
final JSONObject arg = data;
mainHandler.post(() -> {
if (methodChannel == null) return;
methodChannel.invokeMethod("onReceiveData", arg);
});
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down

0 comments on commit 0703733

Please sign in to comment.