[AC-6111] onActivityResult method for KrollModule
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | n/a |
Status | Closed |
Resolution | Done |
Resolution Date | 2019-01-24T20:14:48.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Rainer Schleevoigt |
Assignee | Shak Hossain |
Created | 2019-01-21T09:18:20.000+0000 |
Updated | 2019-01-24T20:14:54.000+0000 |
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:
activitySupport.launchActivityForResult(intent,REQUEST_CODE, new ResultHandler());
The intent contains the new activity.
Some 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.
I 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.
Hoe I can resolve this problem?
Now I have decompiled the SDK and now I know the name of new activity class and I can use:
Ok in this project I could solve, but in common cases, how can I receive
onActivityResult
?Have a look at our "ti.barcode" module as an example here... https://github.com/appcelerator-modules/ti.barcode/blob/master/android/src/ti/barcode/BarcodeModule.java Particularly the code here... https://github.com/appcelerator-modules/ti.barcode/blob/master/android/src/ti/barcode/BarcodeModule.java#L321 You'll first to acquire a unique result code from the
TiActivitySupport
Java class via itsgetUniqueResultCode()
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). The 3rd argument you provide to theTiActivitySupport.launchActivityForResult()
method is an instance ofTiActivityResultHandler
. You need to implement itsonResult()
andonError()
methods on your end because they'll be called when a result has been received or if it failed to launch the child activity. https://docs.appcelerator.com/module-apidoc/latest/android/org/appcelerator/titanium/util/TiActivityResultHandler.html The above mentioned "ti.barcode" module'sBarcodeModule
class implements theTiActivityResultHandler
itself. You can do it this way too or implement your own handler.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)
. Now I have decompiled the SDK and I see the name of the activity and it is public. So I can use the common pattern. Unfortunately 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. Here the code: https://github.com/AppWerft/Ti.Fidel/blob/master/android/src/ti/fidel/TifidelModule.java#L124-L143 Do you have an idea?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? Let'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 itsonActivityResult()
method called with the given request code. That's how it's supposed to be done natively. So, does the 3rd party library not allow you to do this? What is thisshow(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.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:
and the handling of result here: https://gist.github.com/AppWerft/d6f7571b04b28b62c1168dd85fc96f8d Many thanks for you help,you comment solves my issue!
Glad you got it working! Happy to help. :)