Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

If multiple requests are made, it results in a crash because pendingResult is set to null #14

Open
kdheepak opened this issue Jan 11, 2019 · 0 comments

Comments

@kdheepak
Copy link

I had to modify the following

  @Override
  public void onMethodCall(MethodCall call, Result result) {
    if (call.method.equals("selectContact")) {
      if (pendingResult != null) {
        pendingResult.error("multiple_requests", "Cancelled by a second request.", null);
        pendingResult = null;
      }
      pendingResult = result;

      Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
      activity.startActivityForResult(i, PICK_CONTACT);
    } else {
      result.notImplemented();
    }
  }

to this instead for it to work

  @Override
  public void onMethodCall(MethodCall call, Result result) {
    if (call.method.equals("selectContact")) {
      if (pendingResult == null) {
        pendingResult = result;
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
        activity.startActivityForResult(i, PICK_CONTACT);
      } else {
        Log.v("ContactPickerPlugin", "Multiple requests may have been made");
      }
    } else {
      result.notImplemented();
    }
  }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant