首页 > 解决方案 > AsyncTask not getting executed more than one

问题描述

i am initiating direction api to draw polyline,calling asyncTask in oncreate, but its not getting called second time onwords even opening activity again and again. after removing app from recent apps and opening it again works for a single time.here is my code.

    private void moveCamera(LatLng originLatLng, LatLng endLatLng) {
        mMap.addMarker(new MarkerOptions().position(currentLatLng).title("Starting Location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.pickup_location)));
        HelperFunctions.addOverlay(currentLatLng, mMap, SpeedMediatorActivity.this);
        if (endLatLng != null) {
            mMap.addMarker(new MarkerOptions().position(destLatlng).title("Destination Location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.pickup_location)));
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.include(originLatLng);
            builder.include(endLatLng);
            LatLngBounds bounds = builder.build();

            int padding = 50; // offset from edges of the map in pixels
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
            mMap.animateCamera(cu);

            String url = getDirectionsUrl(currentLatLng, destLatlng);
            // Start downloading json data from Google Directions API
            new DownloadTask().execute(url);
        } else {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(originLatLng, 16));
        }

//        new FetchURL(SpeedMediatorActivity.this).execute(getUrl(originLatLng, endLatLng, "driving"), "driving");
    }

Can someone help me please.

标签: androidpolylinedirectiongoogle-directions-api

解决方案


推荐阅读