Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:43:56+00:00 2026-06-02T00:43:56+00:00

Hi my MapView app takes a long time to load up so I wanted

  • 0

Hi my MapView app takes a long time to load up so I wanted to display a horizontal style ProgressDialog whilst it loads up. When I tried to display the dialog in the onCreate/onStart methods the dialog just showed up at the end with 100% complete, I now realise this is because nothing is drawn to the screen until after the onCreate/onStart methods.

So what I would like to do is display the basic map and then execute the demanding code after the map as been drawn and so I can also display a ProgressDialog. Is this possible and how if it is?

Thanks in advance! =]

EDIT:

Here is the source code:

public class GoogleMapsActivity extends MapActivity {
     private List<Overlay>  mapOverlays;

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          MapView mapView = (MapView) findViewById(R.id.mapview);
          mapView.setBuiltInZoomControls(true);
          mapView.setSatellite(false);
          mapView.setTraffic(false);

          mapOverlays = mapView.getOverlays();

          new ProgressTask(this).execute();
    }

    public void addToMap(ItemizedOverlay<OverlayItem> itemizedOverlay){
         mapOverlays.add(itemizedOverlay);
    }
}

And the AsyncTask Class

public class ProgressTask extends AsyncTask<String, Void, Boolean> {

    private ProgressDialog dialog;
    private GoogleMapsActivity activity;

    public ProgressTask(GoogleMapsActivity activity) {
        this.activity = activity;
        dialog = new ProgressDialog(activity);
    }

    @Override
    protected void onPreExecute() {
        dialog.setTitle("Loading Pictures");
        dialog.setMessage("Loading...");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setCancelable(false);
        dialog.show();
    }

    @Override
    protected void onPostExecute(final Boolean sucess) {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    @Override
    protected Boolean doInBackground(String... args) {
        try {

            ArrayList<String> list = getImageLocations();

            String filePath;
            String title;

            LayerDrawable drawable;
            ImageItemizedOverlay itemizedOverlay;

            GeoPoint point;
            OverlayItem overlayItem;

            int count = 0;

            if (list.size() > 0) {
                dialog.setMax(list.size());

                for (String s : list) {
                    filePath = s;
                    point = getImageGeoPoint(s);

                    if (point != null) {
                        title = s.substring(filePath.lastIndexOf("/") + 1);

                        drawable = createLayerDrawable(filePath);

                        itemizedOverlay = new ImageItemizedOverlay(drawable, activity, filePath);

                        overlayItem = new OverlayItem(point, title, null);

                        itemizedOverlay.addOverlay(overlayItem);
                        activity.addToMap(itemizedOverlay);
                    } 
                    dialog.incrementProgressBy(1);
                }

            } else {
                if(dialog.isShowing())
                    dialog.dismiss();

                CharSequence text = "No pictures with geolocations stored at DCIM/Camera.";
                Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG);
                toast.show();
            }
            CharSequence text = count + " pictures didn't have a geolocation.";
            Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG);
            toast.show();
            return true;
        } catch (Exception e) {
            Log.e("tag", "error: " + e.toString(), e);
            return false;
        }
    }

    private LayerDrawable createLayerDrawable(String filePath) {

        Bitmap bitmap = BitmapFactory.decodeFile(filePath);
        Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, 50, 50);

        Drawable picture = new BitmapDrawable(thumbnail);

        Drawable pin = activity.getResources()
                .getDrawable(R.drawable.backgroundpin);

        InsetDrawable inset = new InsetDrawable(picture, 11, 15, 11, 23);
        Drawable[] list = { pin, inset };

        LayerDrawable layer = new LayerDrawable(list);

        return layer;
    }

    private static GeoPoint getImageGeoPoint(String filename) {
        GeoPoint gp = null;
        float[] latlong = new float[2];

        try {
            ExifInterface tag = new ExifInterface(filename);

            if (tag.getLatLong(latlong)) {
                gp = new GeoPoint((int) (latlong[0] * 1E6),
                        (int) (latlong[1] * 1E6));
            } else {
                // TODO error!
            }

        } catch (FileNotFoundException fnf) {
            // TODO error!
            fnf.printStackTrace();
        } catch (IOException io) {
            // TODO error!
            io.printStackTrace();
        }

        return gp;
    }

    private static ArrayList<String> getImageLocations() {
        File directory = new File("mnt/sdcard/DCIM/Camera");

        FilenameFilter imageFilter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                String lowercaseName = name.toLowerCase();
                if (lowercaseName.endsWith(".jpg")) {
                    return true;
                } else {
                    return false;
                }
            }
        };

        File[] files = directory.listFiles(imageFilter);
        ArrayList<String> paths = new ArrayList<String>();

        if (files != null && files.length > 0)
            for (File f : files) {
                paths.add(f.getAbsolutePath());
            }

        return paths;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:43:58+00:00Added an answer on June 2, 2026 at 12:43 am

    If you need to run expensive code, it should be executed on a background thread to prevent your UI from locking up. To have some UI elements display related to this process, Android provides the AsyncTask class for this very purpose.

    To show a ProgressDialog, implements onPreExecute() in your AsyncTask implementation and create and show the dialog, then in onPostExecute(), dismiss it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app on the android market, which uses the mapview to display
I have a mapview in my app. My requirement is each time when I
I have an android app that takes an array from a website {d:[{latitude:-1.0,longitude:-1.0,time:07:14 PM
I have an app that has a mapview, and it shows 20 pins (from
I've got an app that uses MapView and I print out the user's latitude,
I am working on an Android app that utilizes the Google Maps API MapView,
Currently, my app has a mapview that creates a new MyLocationOverlay in the onCreate
In my app mapview works great on some phones and very poorly on other
I am doing an app based on mapview. I am getting the location(place) and
Hello i have a mapView and i think it takes too much memory after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.