@Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        final int itemId = item.getItemId();
        if (itemId == R.id.menu_item_save) {
            AndroidRxUtils.andThenOnUi(Schedulers.io(), () -> DataStore.saveIndividualRoute(routeItemAdapter.getItems()), () -> {
                originalRouteItems = new ArrayList<>(routeItemAdapter.getItems());
                invalidateOptionsMenu();
                ViewUtils.showShortToast(this, R.string.sorted_route_saved);
                finish();
            });
            return true;
        } else if (itemId == R.id.menu_item_cancel) {
            finish();
            return true;
        } else if (itemId == R.id.menu_invert_order) {
            invertOrder();
            return true;
        } else if (itemId == R.id.menu_optimize) {
            optimizeRoute();
            return true;
        } else if (itemId == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return false;
    }
experimental function for optimizing a route by using tsp-specific algorithm
main/src/main/java/cgeo/geocaching/maps/routing/RouteSortActivity.java