Skip to content

Commit

Permalink
Merge pull request #410 from Junglee-Faisal/master
Browse files Browse the repository at this point in the history
fixed: reply already sent and a possible ANR
  • Loading branch information
RodrigoSMarques authored Jan 16, 2025
2 parents cd040ab + 4ba8520 commit a419f17
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
public class MethodResultWrapper implements MethodChannel.Result {
private final MethodChannel.Result methodResult;
private final Handler handler;
private boolean called;

MethodResultWrapper(MethodChannel.Result result) {
methodResult = result;
handler = new Handler(Looper.getMainLooper());
}

private synchronized boolean checkNotCalled() {
if (called) {
return false;
}
called = true;
return true;
}

@Override
public void success(final Object result) {
if (!checkNotCalled()) {
return;
}
handler.post(
new Runnable() {
@Override
Expand All @@ -33,6 +45,9 @@ public void run() {
@Override
public void error(
final String errorCode, final String errorMessage, final Object errorDetails) {
if (!checkNotCalled()) {
return;
}
handler.post(
new Runnable() {
@Override
Expand All @@ -48,6 +63,9 @@ public void run() {

@Override
public void notImplemented() {
if (!checkNotCalled()) {
return;
}
handler.post(
new Runnable() {
@Override
Expand Down

0 comments on commit a419f17

Please sign in to comment.