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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:06:14+00:00 2026-06-05T23:06:14+00:00

My MapView solution in a Fragment is largely based on the examples provided by

  • 0

My MapView solution in a Fragment is largely based on the examples provided by ChristophK, user1414726 and inazaruk in this SO post: mapview-in-a-fragment

When onPause() is called in the Fragment, some cleanup is done to avoid IllegalArgumentException. Code in onPause and onStop:

if (mapViewContainer != null) {
mapViewContainer.setVisibility(View.GONE);
((ViewGroup) mapViewContainer.getParent()).removeView(mapViewContainer);
mapViewContainer = null;
}

This works fine when onPause is called while swiping to other Fragments, because onCreateView(..) gets overridden in the Fragment when MapActivity is visible again, where mapViewContainer is reinstantiated.

But when I turn the screen off; onCreateView(..) does not get overridden when the screen is powered back on (onPaused and onResume calls works fine). This causes the MapView to display black, because the view is null from the removeView call in onPause, until onCreateView(..) is called again after some interaction.

How can I force onCreateView to override or in some way to add the MapView back to the Fragment when screen powers back on?

Code inside onCreateView(..):

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// This is where you specify you activity class
Intent i = new Intent(getActivity(), MapTabActivity.class);
Window w = mLocalActivityManager.startActivity("tag", i);
mapViewContainer = w.getDecorView();
mapViewContainer.setVisibility(View.VISIBLE);
mapViewContainer.setFocusableInTouchMode(true);
((ViewGroup)
mapViewContainer).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
return mapViewContainer; }

Cheers.

  • 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-05T23:06:15+00:00Added an answer on June 5, 2026 at 11:06 pm

    I might have found an answer to our problem. I don’t think it’s a good one, but it seems to work..

    If you save a reference to the mapViewContainer’s parent (I made it static) in onStart() you can add the mapViewContainer to the parent in onResume() if it’s not already contained.

    Here is what I did:

    private static ViewParent parent;
    @Override
    public void onStart() {
        super.onStart();
    
        parent = mapViewContainer.getParent();      
    
    }
    
    @Override
    public void onResume() {
        super.onResume();
    
    
        if(mapViewContainer != null && parent != null && ((FrameLayout) parent).findViewById(mapViewContainer.getId()) == null) {
            ((FrameLayout) parent).addView(mapViewContainer);
        }
    }
    

    In onPause() I do not set mapViewContainer == null, so I can reuse it.

    If you have any suggestion to improve this ‘solution’ you’re very welcome!

    Hope it helps.

    CHEERS

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

Sidebar

Related Questions

I searched other post like this, but I didn't find a solution. Anyone know
I have a MapView that will contain alot of overlays. For this i've extended
In my app mapview works great on some phones and very poorly on other
Will you guys tell me whether or not this solution will work before I
Is there any solution for using the a MapView (and thus the MapActivity )
UPDATE 07/12/2011: I figured it out. Will post solution as soon as I'm finished
I'm currently making an android map based app. The purpose of this app is
My application uses a MapView which will display multiple places. I have the latitude
I have a MapView where Drawable markers are placed with a limit set to
When I open MapView with navigationcontroller in a new view, then not waiting till

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.