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 9238641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:48:33+00:00 2026-06-18T07:48:33+00:00

I’ve a problem with a Fragment that embeds the SuportMapFragment from the new Google

  • 0

I’ve a problem with a Fragment that embeds the SuportMapFragment from the new Google Maps API. When my fragment is created it fetches some data in an AsyncTask beginning in the onResume method. While this happens the MapFragment remains off-screen, instead a progress bar is displayed.

When the AsyncTask is completed, I register with the onGlobalLayout event of the mapView. Then I display the fragment, which results in the map view being shown and layouted. onGlobalLayout is triggered and the animation starts.

This worked fine for quite some time, until I started optimizing the operations in the data gathering AsyncTask to complete almost instantaneously. Now the app will often crash when started, more often in Release than Debug, which is why I think that I’m dealing with a racing condition here that I’m not aware of.

The exception reads:

Map size should not be 0. Most likely, layout has not yet occured for the map view.

Any insights are greatly appreciated.

For reference: This is the code that seems to cause the crash:

// Hide status UI
this.progressBar.setVisibility(View.INVISIBLE);
this.statusTextView.setVisibility(View.INVISIBLE);

// Update state
this.uraDataDownloadFinished = true;

// Schedule map translation to occur when layout is complete
final View mapView = this.mapFragment.getView();
if (mapView.getViewTreeObserver().isAlive())
{
    mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
    {
        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi") // We check which build version we are using.
        @Override
        public void onGlobalLayout()
        {
            Log.d(TAG, "onGlobalLayout()");
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            {
              mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            else
            {
              mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            // here we crash
            this.map.animateCamera(
                    CameraUpdateFactory.newLatLngBounds(
                            LatLngBounds.builder()
                                .include(topLeft)
                                .include(topRight)
                                .include(bottomLeft)
                                .include(bottomRight)
                                .build(),
                            0),
                    durationMs,
                    null);
        }
   });
}

// Show map (which will eventually trigger onGlobalLayout)
this.getFragmentManager().beginTransaction().show(this.mapFragment).commit();
this.mapFragment.getMap().setOnCameraChangeListener(this);

Thanks a lot!

  • 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-18T07:48:34+00:00Added an answer on June 18, 2026 at 7:48 am

    I am not sure but as you are using AsyncTask is probably that you are trying to get map bounds before map has undergone layout.

    You can see the documentation, it suggest to use newLatLngBounds(boundary, width, height, padding) instead .

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.