Skip to content

onActivityResult is never called after startActivityForResult #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tms-martins opened this issue Apr 4, 2018 · 4 comments
Closed

onActivityResult is never called after startActivityForResult #452

tms-martins opened this issue Apr 4, 2018 · 4 comments

Comments

@tms-martins
Copy link

For activities like turning on Bluetooth or picking a contact, developers must call startActivityForResult, and handle the result in onActivityResult.

In the following snippet, tapping the screen starts an activity to pick a contact. The system's contact picker appears, a contact can be selected (or the process cancelled), returning to the app. However, the overridden method onActivityResult never seems to be called.

(it also seems that mousePressed() isn't called if there is no draw() function)

Processing 3.3.6
Android Mode 4.0.1
Tested on:

  • Motorola Moto G2, Android 6.0.0 (original rom)
  • Motorola Moto G2, Android 7.1.2 (custom rom)
  • Huawei P Smart, Android 8.0.0 (original rom)
public static final int PICK_CONTACT = 57291;

void mousePressed() {
  println("mousePressed()");
  pickContact();
}

void pickContact() {
  println("pickContact()");
  Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
  intent.setType(Phone.CONTENT_TYPE);  //should filter only contacts with phone numbers
  super.getActivity().startActivityForResult(intent, PICK_CONTACT);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  println("onActivityResult() for code <" + requestCode + ">"); 
  super.onActivityResult(requestCode, resultCode, data);
}
@kfrajer
Copy link
Contributor

kfrajer commented Apr 13, 2018

(it also seems that mousePressed() isn't called if there is no draw() function)

You need to provide an empty draw (at a minimum) for Processing events to be handled at all. Try with draw(){ } and see if it fixes your current problem. I suggest you check the implementation of B2 in the Ketai library. There is an example there, or check Ketai.org

Kf

@tms-martins
Copy link
Author

Thanks! I didn't post the complete sketch, but it does have an empty-bodied draw() as you suggested.
So, to clarify, mousePressed() does get called, and so does pickContact().
The main issue persists, i.e., onActivityResult() doesn't seem to be called afterwards.

@codeanticode
Copy link
Contributor

I can reproduce this issue, thanks. I think the solution is to add the implementation of onActivityResult(int requestCode, int resultCode, Intent data) to the template main activity, so it calls the corresponding method in PApplet (remember that PApplet itself is not an activity).

@codeanticode
Copy link
Contributor

Fixed with f452ad6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants