2

I'm using startActivityForResult / onActivityResult to communicate between two apps on Google Glass.

Calling code:

Intent intentScan = new Intent("com.github.barcodeeye.SCAN");
intentScan.setPackage("com.github.barcodeeye");
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
intentScan.putExtra("RESULT_DISPLAY_DURATION_MS", 1000L);
intentScan.putExtra("SAVE_HISTORY", false);
intentScan.putExtra("PROMPT_MESSAGE", "Scan MQTT Config Code");

startActivityForResult(intentScan, 333);

Response code:

    activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
    activity.finish();

onActivityResult

    if (requestCode == 333 && resultCode == RESULT_OK)
        processQRCode(data);

I debugged through both apps, the called app gets to setResult and finish, but onActivityResult is never called

What can cause this?

(I'm calling a fork of the BarcodeEye project that re-enables the ability to call it through intents: https://github.com/paulpv/BarcodeEye/tree/intent)

kolosy
  • 3,029
  • 3
  • 29
  • 48
  • Could you include your `onActivityResult()` code? – nKn Apr 24 '14 at 16:17
  • I can, but... it clearly has nothing to do with the issue, as it never gets called. – kolosy Apr 24 '14 at 16:23
  • Well, then I'll ask it another way: is your `onResultActivity()` defined this way? `public void startActivityForResult (Intent intent, int requestCode, Bundle options)` – nKn Apr 24 '14 at 16:26
  • fair. yes, and it gets called for other `startActivityForResult()` calls. In those cases, the called activity is hosted within my app, here it's a different app. That's the only real difference I can spot. – kolosy Apr 24 '14 at 16:27
  • Shouldn't be an issue. Is there any class implementation difference? I mean, you're calling `startActivityForResult()` from an `Activity` and the other app calls a `Fragment` or something similar? – nKn Apr 24 '14 at 16:52
  • nope. Activity -> Activity. – kolosy Apr 24 '14 at 17:00
  • Might this have something to do with it? http://stackoverflow.com/questions/9556206/using-startactivityforresult-across-android-applications – nKn Apr 24 '14 at 18:30
  • no. he's getting the callback, just doesn't know what format. i'm not getting a callback. – kolosy Apr 24 '14 at 20:19

1 Answers1

0

As with the vast majority of similar questions about returning content across activities on SO, the issue was with my code. I was calling from inside a menu activity, and was calling finish() right after the startActivityForResult() call. Clearly, that meant no one was listening when the response came back.

kolosy
  • 3,029
  • 3
  • 29
  • 48