[AC-6202] Android: TiActivitySupport support startResolutionForResult
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | n/a |
Status | Closed |
Resolution | Needs more info |
Resolution Date | 2019-06-10T23:45:24.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Ahmed Mohamed |
Assignee | Joshua Quick |
Created | 2019-04-07T16:46:47.000+0000 |
Updated | 2021-02-02T14:08:00.000+0000 |
Description
In my com.locationservices module I can't get onActivityResult by using TiActivitySupport because it doesn't support startResolutionForResult void from ResolvableApiException
https://github.com/AhmedMSayed/TiLocationServices/blob/master/android/src/com/locationservices/LocationservicesModule.java
Hello [~ahmed.mohamed20320], Can you share some native guide on how this is handled in there? Thanks.
ResolvableApiException provides a method to resolves an error by starting any intents requiring user interaction. [See Description here](https://developers.google.com/android/reference/com/google/android/gms/common/api/ResolvableApiException) startResolutionForResult is a method like startActivityForResult method which used to start an activity and wait for a result that will be catched later in onActivityResult method. At now Titanium support startActivityForResult by using launchActivityForResult method in TiActivitySupport and catched the results by onResult So we need to support startResolutionForResult to get its results too in onResult You can test it on my module [here](https://github.com/AhmedMSayed/TiLocationServices/blob/5a46495ee567d6ca91a8cc727a21dbd0f5146651/android/src/com/locationservices/LocationservicesModule.java#L137)
This is possible to do now. Instead of using the
TiActivitySupportHelper.launchActivityForResult()
method, you'll want to create your own version of that code. You'll need to create your ownTiActivityResultHandler
object, pass it into theTiActivitySupportHelper.registerResultHandler()
method (which Titanium's activity queries in itsonActivityResult()
method, and then call thestartResolutionForResult()
with the request code and activity you are launching it from. I can write up a code example tomorrow.In your code, get rid of this part...
And do this instead...
Unfortunately our Titanium activity's
addOnActivityResultListener()
method stores the listener as a weak reference. So, you need to hold on to the listener as a strong reference temporarily viafinal
. I'm doing it by boxing it above. Alternatively, you can implement theOnActivityResultEvent
via yourLocationservicesModule
class but then you have to change the request code handling. I hope this helps!Hello [~ahmed.mohamed20320], Can you follow up here? what's the status of your issue? did you try Han's guide?
Thanks @Joshua Quick it works like a charm. https://github.com/AhmedMSayed/ti.locationservices/blob/7d65d126e43c1bf600530ee4a0c841c850fe4388/android/src/ti/locationservices/TiLocationservicesModule.java#L120