tmsbn90

Question regarding usage of Async Callbacks for NA Operations

Discussion created by tmsbn90 on Jun 10, 2014
Hi Guys,

Consider the below code

RouteTask routeTask=RouteTask.createOnlineRouteTask(url,null);
RouteParameters routeParameters=routeTask.retrieveDefaultRouteTaskParameters();
[insert code to set the route stops]
routeTask.solve(routeParameters,new CallbackListener<RouteResult>() {
            @Override
            public void onCallback(RouteResult routeResult) {
                
            }

            @Override
            public void onError(Throwable throwable) {

                 runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(DashboardActivity.this, throwable.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

            }
        });



1. I noticed that without explicitly including a runOnUiThread statement, the Toast(or any UI related functionality) will not work inside the callback methods . Is this a bug or is this by design? Shouldn't the callbacks always run on the UI thread?

2. To perform a route Task, an instance of RouteParameters is required.  From my understanding, the only way to initialise a routeParameter object is by using the retrieveDefaultRouteTaskParameters() method which is a network operation. Since there is no built-in asynchronous callback to perform  retrieveDefaultRouteTaskParameters(), developers will HAVE to create an AsyncTask(or Handler) to perform this operation,  so doesn't this defeat the purpose of having an async callback to solve a route task? (the same AsyncTask created earlier can be used here)

The Esri sample for routing don't make use of the async methods so please correct me if I am missing something obvious here

Outcomes