AnsweredAssumed Answered

"ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask

Question asked by rameshbachiraju on Aug 15, 2019
Latest reply on Jul 3, 2020 by appdev_fdsu

We are using ARCGIS Android SDK 100.5

We try to fetch the token using rest api 

             https://www.arcgis.com/sharing/rest/oauth2/token

and create UserCredentials object using token and referrer (unfortunately referrer cannot be nil in Android unlike IOS). 

 

We are assigning the credentials to an online RouteTask 

 

val routeTask = RouteTask(appContext, "http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")
val credential = UserCredential.createFromToken(accessToken, "www.arcgis.com")
routeTask.credential = credential

 

 

We are getting exception :

 

"ArcGISRuntimeException: Cannot call this method in this context" whenever we try to get route parameters from routeTask.

 

for this method

 

val routeParameters = routeTask?.createDefaultParametersAsync()?.get()

 

Please note that we are following similar approach in IOS and it is working fine.

 

Any hints or suggestion on why this exception is coming?

Outcomes