[TIMOB-26752] Android: Add support for `onActivityResult` callback method for activity
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Prashant Saini |
Assignee | Eric Merriman |
Created | 2018-12-14T05:25:46.000+0000 |
Updated | 2019-01-28T22:16:15.000+0000 |
Description
Currently we have onCreate, onPause, onResume, etc callback methods available for an activity, but we do not have any *onActivityResult* callback method due to which many things are not doable easily and straight-forward in Titanium.
e.g.
1- Google Location API library allows to enable location from within the app itself without going into the device settings. But this API call returns the result in native *onActivityResult* method.
2- Some image-cropping or scanner libraries' results are returned in native *onActivityResult* method. (https://github.com/ArthurHub/Android-Image-Cropper)
At present, we cannot achieve this without creating modules which is cumbersome when we already have Hyperloop.
With Hyperloop we can call native *startActivityForResult* method on third-party libraries but we cannot get their results back to the activity as Hyperloop is unable to let us define *TiActivityResultHandler* interface methods nor we can cast a native Intent to Titanium intent so we can use Titanium's *startActivityForResult* method callback.
It makes Hyperloop less usable if anything is to be returned in
onActivityResult
method. We hope to see this improvement in SDK 8.x.x itself as it will give more flexibilities in using Hyperloop.
Alternatively, you can use Titanium's
Ti.Android.Activity.startActivityForResult()
JavaScript method. It's 2nd argument accepts a callback which will be called by Titanium's internalonActivityResult()
method. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Activity-method-startActivityForResult Are you able to use this approach instead?I have the same issue with a third party SDK. The interace calls a methd with one paramter (currentActivity) and send the result to onActivityResult... The SDK opens a new activity by Fidel.present(TiApplication.getInstance().getCurrentActivity()); https://github.com/FidelLimited/fidel-android Need support.
I cannot use
startActivityForResult()
because the SDK only exports the method for opening the new activity, the activity self is private and I have no access. Is there a solution without patch of Titanium SDK?Any update here? I am trying to use the [Matisse](https://github.com/zhihu/Matisse/) library which returns data via this callback. I tried hooking into the lifecycle like Ti.Facebook does [here](https://github.com/appcelerator-modules/ti.facebook/blob/master/android/src/facebook/ActivityWorkerProxy.java#L51), but it doesn't seem to be called. Unfortunately, the
public void onCreate(Activity activity, Bundle savedInstanceState)
signature is only available inKrollProxy
instances, notKrollModule
ones. So I usedpublic void onStart(Activity activity)
there, but it doesn't get called either. My code:My class
implements
bothOnActivityResultEvent
andOnInstanceStateEvent
. *EDIT*: Found a proper way!If onCreate is only available for proxies then we could implement the interface in a proxy. I implemented Ti.Paypal with this pattern. In my project I decompiled the aar, found the name of new activity and used it in
launchActivityForResult
and
and
What I have understood: You try to add this listener in onStart, but it will not called.
Let's not hijack [~prashant_saini]'s ticket please. It might cause confusion. This ticket is about doing this 100% in JavaScript and hyperloop, without having to write any Java code. [~hknoechel], [~titanium@webmasterei-hamburg.de], it looks like you 2 are coding in Java... in which case, there is a solution available to you now. [~titanium@webmasterei-hamburg.de], I believe I've already helped you in ticket [AC-6111]? If not, perhaps we can continue our conversation there if you don't mind. [~hknoechel], perhaps what I've written there might help you too, but it sounds like you have already solved it. (I'm recommending that you use "ti.barcode" as an example since it's simpler.)
My issue is solved because I could read the class name from decompiled jar. Sorry for "hijacking" this was not my intrention.
No worries. :)