<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: &amp;quot;ArcGISRuntimeException: Cannot call this method in this context&amp;quot;:when calling createDefaultParametersAsync() for online RouteTask in ArcGIS Runtime SDK for Android Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748562#M5256</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My hardcoded user credentials in the above code sample were just to show the done loading pattern, as I explained this is not recommended in a real app.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You shouldn't need to use the rest API directly to use oAuth.&amp;nbsp; Have you seen this samples code:&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/android/latest/java/sample-code/authenticate-with-oauth/" title="https://developers.arcgis.com/android/latest/java/sample-code/authenticate-with-oauth/"&gt;Authenticate with OAuth | ArcGIS for Developers&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code is on git&amp;nbsp;&lt;A class="link-titled" href="https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/authenticate-with-oauth" title="https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/authenticate-with-oauth"&gt;arcgis-runtime-samples-android/java/authenticate-with-oauth at master · Esri/arcgis-runtime-samples-android · GitHub&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ChallengeHandlers are what we use for this.&amp;nbsp; You can use the DefaultChallengeHander as in the example linked above, or you could write your own.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Aug 2019 14:21:42 GMT</pubDate>
    <dc:creator>MarkBaird</dc:creator>
    <dc:date>2019-08-16T14:21:42Z</dc:date>
    <item>
      <title>"ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748559#M5253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using ARCGIS Android SDK 100.5&lt;/P&gt;&lt;P&gt;We try to fetch the token using rest api&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #c41a16; background-color: #f8f8f8;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;https://www.arcgis.com/sharing/rest/oauth2/token&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f8f8f8; color: #3d3d3d; "&gt;and create&amp;nbsp;UserCredentials object using token and referrer (unfortunately referrer cannot be nil in Android unlike IOS).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are assigning the credentials to an online RouteTask&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val routeTask = RouteTask(appContext, "http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")&lt;BR /&gt; val credential = UserCredential.createFromToken(accessToken, "www.arcgis.com")&lt;BR /&gt; routeTask.credential = credential&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are getting exception :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"ArcGISRuntimeException: Cannot call this method in this context" whenever we try to get route parameters from routeTask.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for this method&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val routeParameters = routeTask?.createDefaultParametersAsync()?.get()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note that we are following similar approach in IOS and it is working fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any hints or suggestion on why this exception is coming?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Aug 2019 06:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748559#M5253</guid>
      <dc:creator>RAMESHBACHIRAJU</dc:creator>
      <dc:date>2019-08-16T06:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: "ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748560#M5254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ramesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've had a play with this code and I suspect what is happening is the RouteTask is failing to load so you are going ahead and reading the default parameters on a service which isn't working.&amp;nbsp; You need to perform some more checks in your code.&amp;nbsp; I would also apply the same checks in your iOS app as it would fail in the same way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Kotlin skills are not perfect so I've tried to explain this in Java code, but the concept will be the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have connected to the route service using the following code.&amp;nbsp; This is for demo purposes only and I'd recommend using Oauth instead for obvious reasons:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;UserCredential userCredential = &lt;SPAN style="color: #cc7832;"&gt;new &lt;/SPAN&gt;UserCredential(&lt;SPAN style="color: #6a8759;"&gt;"username"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"password"&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;RouteTask routeTask = &lt;SPAN style="color: #cc7832;"&gt;new &lt;/SPAN&gt;RouteTask(&lt;SPAN style="color: #6a8759;"&gt;"http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;routeTask.setCredential(userCredential)&lt;SPAN style="color: #cc7832;"&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;You should then load the route task and listen into the done loading listener:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;routeTask.loadAsync()&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;routeTask.addDoneLoadingListener(()-&amp;gt; {&lt;/PRE&gt;&lt;P&gt;At this point in the code you have either loaded the service or something might have gone wrong!&amp;nbsp; You need to check the load status.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;  &lt;SPAN style="color: #cc7832;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #b389c5;"&gt;routeTask&lt;/SPAN&gt;.getLoadStatus() == LoadStatus.&lt;SPAN style="color: #9876aa;"&gt;LOADED&lt;/SPAN&gt;) {&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;try &lt;/SPAN&gt;{
      RouteParameters routeParameters = &lt;SPAN style="color: #b389c5;"&gt;routeTask&lt;/SPAN&gt;.createDefaultParametersAsync().get()&lt;SPAN style="color: #cc7832;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;} &lt;SPAN style="color: #cc7832;"&gt;catch &lt;/SPAN&gt;(InterruptedException e) {
      e.printStackTrace()&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;} &lt;SPAN style="color: #cc7832;"&gt;catch &lt;/SPAN&gt;(ExecutionException e) {
      e.printStackTrace()&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;}
  } &lt;SPAN style="color: #cc7832;"&gt;else &lt;/SPAN&gt;{
    &lt;SPAN style="color: #808080;"&gt;// failed to load so lets report the error
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;System.&lt;SPAN style="color: #9876aa;"&gt;out&lt;/SPAN&gt;.println(&lt;SPAN style="color: #6a8759;"&gt;"error  " &lt;/SPAN&gt;+ &lt;SPAN style="color: #b389c5;"&gt;routeTask&lt;/SPAN&gt;.getLoadError().getCause())&lt;SPAN style="color: #cc7832;"&gt;;
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;}

})&lt;SPAN style="color: #cc7832;"&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;So you can see above that if you have got a successful connection the service you can read the default parameters.&amp;nbsp; If not the error will display on the console.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you directly run the code above which obviously has a poor user credential you will see:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;--&amp;nbsp; loaded FAILED_TO_LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp;--&amp;nbsp; error com.esri.arcgisruntime.io.JsonEmbeddedException: Unable to generate token.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you leave the user credential out you might see&lt;/P&gt;&lt;P&gt;&amp;nbsp;--&amp;nbsp;error&amp;nbsp; com.esri.arcgisruntime.io.JsonEmbeddedException: Token Required&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The iOS SDK for runtime uses the same pattern for checking the loading of services.&amp;nbsp; This will help to explain it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://developers.arcgis.com/android/latest/guide/loadable-pattern.htm" title="https://developers.arcgis.com/android/latest/guide/loadable-pattern.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for Android | ArcGIS for Developers&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:49:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748560#M5254</guid>
      <dc:creator>MarkBaird</dc:creator>
      <dc:date>2021-12-12T07:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: "ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748561#M5255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the feedback,&amp;nbsp;have modified the code. Kindly note that in the code below I am passing on the token (hard coded for now generated using the API&amp;nbsp;&lt;SPAN style="color: #c41a16; background-color: #f8f8f8; border: 0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2Foauth2%2Ftoken" style="color: #287433; background-color: #f8f8f8; border: 0px; padding: 0px calc(12px + 0.35ex) 0px 0px;" target="_blank"&gt;https://www.arcgis.com/sharing/rest/oauth2/token&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However - loadAsync fails with error saying unable to generate the token&lt;/STRONG&gt;. We do not want to hardcode user name and password. Instead would like to use client_id, and client_secret. As this is not available in Android SDK, we are using rest api to generate the token. We are creating UserCredential object with token. Unfortunately UserCredential doesn't take empty referrer unlike iOS. What should be specified for referrer.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;// Find a route from mStart point to mEnd point.
&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;private void &lt;/SPAN&gt;findRoute() {
    String routeServiceURI = getResources().getString(R.string.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;routing_url&lt;/SPAN&gt;);
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;final &lt;/SPAN&gt;RouteTask solveRouteTask = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;RouteTask(getApplicationContext(), routeServiceURI);
    &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;credential &lt;/SPAN&gt;= UserCredential.&lt;SPAN&gt;createFromToken&lt;/SPAN&gt;(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Q88bbFWwQyx4vuo37xAArEfTjiguvI5kJhm5E4ZJlroboCSX7omF2I-kReJU1dHbDeJz0dWK5CrwO0Jp_bg2--BB_4zZ-D-7mnUcn0tYO5-oPKRbcl3s3GJDvvJnY7l_5h_zHOhHftzl17lmUnVaHw.."&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"ArcGIS.com"&lt;/SPAN&gt;);
    AuthenticationManager.&lt;SPAN&gt;setAuthenticationChallengeHandler&lt;/SPAN&gt;(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;);
    solveRouteTask.setCredential(&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;credential&lt;/SPAN&gt;);
    solveRouteTask.loadAsync();
    solveRouteTask.addDoneLoadingListener(() -&amp;gt; {
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #660e7a;"&gt;solveRouteTask&lt;/SPAN&gt;.getLoadStatus() == LoadStatus.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;LOADED&lt;/SPAN&gt;) {
            &lt;SPAN style="color: #000080; font-weight: bold;"&gt;final &lt;/SPAN&gt;ListenableFuture&amp;lt;RouteParameters&amp;gt; routeParamsFuture = &lt;SPAN style="color: #660e7a;"&gt;solveRouteTask&lt;/SPAN&gt;.createDefaultParametersAsync();
            routeParamsFuture.addDoneListener(() -&amp;gt; {
                &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{
                    RouteParameters routeParameters = &lt;SPAN style="color: #660e7a;"&gt;routeParamsFuture&lt;/SPAN&gt;.get();
                    List&amp;lt;Stop&amp;gt; stops = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;ArrayList&amp;lt;&amp;gt;();
                    stops.add(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;Stop(&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;mStart&lt;/SPAN&gt;));
                    stops.add(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;Stop(&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;mEnd&lt;/SPAN&gt;));
                    routeParameters.setStops(stops);
                    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;final &lt;/SPAN&gt;ListenableFuture&amp;lt;RouteResult&amp;gt; routeResultFuture = &lt;SPAN style="color: #660e7a;"&gt;solveRouteTask&lt;/SPAN&gt;.solveRouteAsync(routeParameters);
                    routeResultFuture.addDoneListener(() -&amp;gt; {
                        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{
                            RouteResult routeResult = &lt;SPAN style="color: #660e7a;"&gt;routeResultFuture&lt;/SPAN&gt;.get();
                            Route firstRoute = routeResult.getRoutes().get(&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;);
                            Polyline routePolyline = firstRoute.getRouteGeometry();
                            SimpleLineSymbol routeSymbol = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;SimpleLineSymbol(SimpleLineSymbol.Style.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;SOLID&lt;/SPAN&gt;, Color.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;BLUE&lt;/SPAN&gt;, &lt;SPAN style="color: #0000ff;"&gt;4.0f&lt;/SPAN&gt;);
                            Graphic routeGraphic = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;Graphic(routePolyline, routeSymbol);
                            &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;mGraphicsOverlay&lt;/SPAN&gt;.getGraphics().add(routeGraphic);
                        } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(InterruptedException | ExecutionException e) {
                            showError(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Solve RouteTask failed " &lt;/SPAN&gt;+ e.getMessage());
                        }
                    });
                } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(InterruptedException | ExecutionException e) {
                    showError(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Cannot create RouteTask parameters " &lt;/SPAN&gt;+ e.getMessage());
                }
            });
        } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{
            showError(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Unable to load RouteTask " &lt;/SPAN&gt;+ &lt;SPAN style="color: #660e7a;"&gt;solveRouteTask&lt;/SPAN&gt;.getLoadError().getCause().toString());
        }
    });
}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808000;"&gt;@Override
&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public &lt;/SPAN&gt;AuthenticationChallengeResponse handleChallenge(AuthenticationChallenge authenticationChallenge) {
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CONTINUE_WITH_CREDENTIAL&lt;/SPAN&gt;, &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;credential&lt;/SPAN&gt;);
}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Is there a mechanism to pass token generated from Rest api to RouteTask ?&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:49:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748561#M5255</guid>
      <dc:creator>RAMESHBACHIRAJU</dc:creator>
      <dc:date>2021-12-12T07:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: "ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748562#M5256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My hardcoded user credentials in the above code sample were just to show the done loading pattern, as I explained this is not recommended in a real app.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You shouldn't need to use the rest API directly to use oAuth.&amp;nbsp; Have you seen this samples code:&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/android/latest/java/sample-code/authenticate-with-oauth/" title="https://developers.arcgis.com/android/latest/java/sample-code/authenticate-with-oauth/"&gt;Authenticate with OAuth | ArcGIS for Developers&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code is on git&amp;nbsp;&lt;A class="link-titled" href="https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/authenticate-with-oauth" title="https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/authenticate-with-oauth"&gt;arcgis-runtime-samples-android/java/authenticate-with-oauth at master · Esri/arcgis-runtime-samples-android · GitHub&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ChallengeHandlers are what we use for this.&amp;nbsp; You can use the DefaultChallengeHander as in the example linked above, or you could write your own.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Aug 2019 14:21:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748562#M5256</guid>
      <dc:creator>MarkBaird</dc:creator>
      <dc:date>2019-08-16T14:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: "ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748563#M5257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We would like to use client-id and client-secret which are not supported by OAuthConfiguration in Android ArcGIS SDK and ArcGIS IOS SDK but are supported in .NET SDK and Rest Api.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only way we can achieve this is by using RestApi to get the&amp;nbsp;token and assign the token through UserCredential class and assign this credential object to RouteTask&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this is not working, LoadAsync throws an Error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on how to manage this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Aug 2019 17:35:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748563#M5257</guid>
      <dc:creator>RAMESHBACHIRAJU</dc:creator>
      <dc:date>2019-08-16T17:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: "ArcGISRuntimeException: Cannot call this method in this context":when calling createDefaultParametersAsync() for online RouteTask</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748564#M5258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/372948"&gt;RAMESH BACHIRAJU&lt;/A&gt;‌.&lt;/P&gt;&lt;P&gt;I am having the same exact problem as you:&lt;BR /&gt;&lt;STRONG&gt;com.esri.arcgisruntime.io.JsonEmbeddedException: Unable to generate token.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Error Code: 22&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am sure the token is fine because i post the URL in a browser like &lt;A href="http://layer_url/0?token=my_token"&gt;http://layer_url/0?token=my_token&lt;/A&gt;&amp;nbsp;and i see the layer information on the browser.&lt;/P&gt;&lt;P&gt;Did you get any solution for this? I would appreciate any help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2020 08:17:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/quot-arcgisruntimeexception-cannot-call-this/m-p/748564#M5258</guid>
      <dc:creator>appdev</dc:creator>
      <dc:date>2020-07-03T08:17:12Z</dc:date>
    </item>
  </channel>
</rss>

