{ "id": "172898", "key": "AC-6111", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "10000", "description": "", "name": "Done" }, "resolutiondate": "2019-01-24T20:14:48.000+0000", "created": "2019-01-21T09:18:20.000+0000", "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2019-01-24T20:14:54.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "Some Third party SDK (i.e. paypal) opens a new activity and sends the result to onActivityResult. For this we can use this pattern:\r\n\r\n```\r\nactivitySupport.launchActivityForResult(intent,REQUEST_CODE, new ResultHandler());\r\n```\r\nThe intent contains the new activity.\r\n\r\nSome other SDKs exposes only the method for opening the new (private) activity (i.e. fidel.uk). In this case I have no access to the activity and I cannot use the pattern above.\r\n\r\nI can only use the open method and the result (aspected in onActivityResult) I cannot access. Krollmodule class expose lifecycle ecents (onPause etc,), but not onActivityResult.\r\n\r\nHoe I can resolve this problem?", "attachment": [], "flagged": false, "summary": "onActivityResult method for KrollModule", "creator": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "environment": "Android", "comment": { "comments": [ { "id": "445521", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "Now I have decompiled the SDK and now I know the name of new activity class and I can use:\r\n\r\n\r\n{code:java}\r\n@Kroll.method\r\npublic void present() {\r\n\tTiActivitySupport support = (TiActivitySupport) TiApplication.getAppCurrentActivity();\r\n\tFidel.FIDEL_LINK_CARD_REQUEST_CODE = support.getUniqueResultCode();\r\n\tsupport.launchActivityForResult(\r\n\t\t\tnew Intent(TiApplication.getInstance().getApplicationContext(), EnterCardDetailsActivity.class),\r\n\t\t\tFidel.FIDEL_LINK_CARD_REQUEST_CODE, new PaymentResultHandler());\r\n}\r\n{code}\r\nOk in this project I could solve, but in common cases, how can I receive `onActivityResult`?", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2019-01-22T09:07:36.000+0000", "updated": "2019-01-22T09:07:36.000+0000" }, { "id": "445537", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Have a look at our \"ti.barcode\" module as an example here...\r\nhttps://github.com/appcelerator-modules/ti.barcode/blob/master/android/src/ti/barcode/BarcodeModule.java\r\n\r\nParticularly the code here...\r\nhttps://github.com/appcelerator-modules/ti.barcode/blob/master/android/src/ti/barcode/BarcodeModule.java#L321\r\n\r\nYou'll first to acquire a unique result code from the {{TiActivitySupport}} Java class via its {{getUniqueResultCode()}} method. You should never hard code the result code on the library side to avoid collision with other libraries. This is standard practice on Android (it's up to the activity implementor to set the unique result codes, not the library).\r\n\r\nThe 3rd argument you provide to the {{TiActivitySupport.launchActivityForResult()}} method is an instance of {{TiActivityResultHandler}}. You need to implement its {{onResult()}} and {{onError()}} methods on your end because they'll be called when a result has been received or if it failed to launch the child activity.\r\nhttps://docs.appcelerator.com/module-apidoc/latest/android/org/appcelerator/titanium/util/TiActivityResultHandler.html\r\n\r\nThe above mentioned \"ti.barcode\" module's {{BarcodeModule}} class implements the {{TiActivityResultHandler}} itself. You can do it this way too or implement your own handler.\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-01-23T02:34:04.000+0000", "updated": "2019-01-23T02:34:04.000+0000" }, { "id": "445549", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "Thanks for your quick answer. But in my use case I cannot start intent because the new activity is not documented. The only documented interface is a method `show(fooactivity)`.\r\n\r\nNow I have decompiled the SDK and I see the name of the activity and it is public. So I can use the common pattern.\r\n\r\nUnfortunately the result event will never fired and after closing the second activity ANR happens, if I don't start the module in the root activity (i.e.) after window opening.\r\nHere the code: https://github.com/AppWerft/Ti.Fidel/blob/master/android/src/ti/fidel/TifidelModule.java#L124-L143\r\n\r\nDo you have an idea?", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2019-01-23T08:43:19.000+0000", "updated": "2019-01-23T08:43:19.000+0000" }, { "id": "445602", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Are you saying this 3rd party activity can't be shown via the native [startActivityForResult()|https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent,%20int)] method?\r\n\r\nLet's forget about Titanium for the moment. In order to receive the activity's result natively, you need to feed the above mentioned method a {{requestCode}}, which is a unique integer ID that is set by the calling activity. Doing so will cause that same activity to have its {{onActivityResult()}} method called with the given request code. That's how it's supposed to be done natively.\r\n\r\nSo, does the 3rd party library not allow you to do this? What is this {{show(activity)}} method that are you speaking of? It sounds like this 3rd party library might be doing something unusual. If so, then they would need to provide a code example on how to do this. If you can provide a link to this library's docs, then we might be able to help out.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-01-23T23:00:06.000+0000", "updated": "2019-01-23T23:00:06.000+0000" }, { "id": "445612", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "The 3party SDK realise a billing interface for creditcards.Therefore there is only a method present() and the result will send to onActivityResult. This is the only interface. Now I have decompiled the aar (I know this is not permitted)and now I know the name of the activity class. Good news: it works:\r\n\r\n\r\n{code:java}\r\n@Kroll.method\r\npublic void present() {\r\n\t_instance = this;\r\n\tfinal TiActivitySupport support = (TiActivitySupport) TiApplication.getAppCurrentActivity();\r\n\tfinal Intent intent = new Intent(TiApplication.getInstance().getApplicationContext(),\r\n\t\t\tEnterCardDetailsActivity.class);\r\n\tFidel.FIDEL_LINK_CARD_REQUEST_CODE = support.getUniqueResultCode();\r\n\tif (TiApplication.isUIThread()) {\r\n\t\tsupport.launchActivityForResult(intent, Fidel.FIDEL_LINK_CARD_REQUEST_CODE, this);\r\n\t} else {\r\n\t\tTiMessenger.postOnMain(new Runnable() {\r\n\t\t\t@Override\r\n\t\t\tpublic void run() {\r\n\t\t\t\tsupport.launchActivityForResult(intent, Fidel.FIDEL_LINK_CARD_REQUEST_CODE, _instance);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n}\r\n{code}\r\n\r\nand the handling of result here: https://gist.github.com/AppWerft/d6f7571b04b28b62c1168dd85fc96f8d\r\n\r\nMany thanks for you help,you comment solves my issue! \r\n\r\n\r\n", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2019-01-24T08:33:04.000+0000", "updated": "2019-01-24T08:33:04.000+0000" }, { "id": "445642", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Glad you got it working! Happy to help. :)", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-01-24T20:14:30.000+0000", "updated": "2019-01-24T20:14:30.000+0000" } ], "maxResults": 7, "total": 7, "startAt": 0 } } }