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

  • Home
  • SEARCH
  • 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 6892267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:30:49+00:00 2026-05-27T06:30:49+00:00

I am using the android compatibility class with the hack for using mapviews in

  • 0

I am using the android compatibility class with the hack for using mapviews in a fragment found here: https://github.com/petedoyle/android-support-v4-googlemaps

Unfortunately, what I am finding is that if the mapfragment gets removed from the activity, and then readded, I get the “You are only allowed to have a single MapView in a MapActivity” error.”

I understand the principle behind the error, and tried destroying the mapview in the fragments onPause method. Unfortunately I can’t seem to destroy the mapview completely, since I am still getting it. My Code looks like this:

private RelativeLayout layout; 
private MapView mp;

public void onResume(){
    super.onResume();
    Bundle args = getArguments();
    if(mp == null)
    {
        mp = new MapView(getActivity(), this.getString(R.string.map_api_key)); 
        mp.setClickable(true);
    }

    String request = args.getString("requestId");
    layout = (RelativeLayout) getView().findViewById(R.id.mapholder);
    layout.addView(mp);
    //TextView txt = (TextView) getView().findViewById(R.id.arguments);
    //txt.setText(request);
}

public void onPause(){
    super.onPause();
    layout.removeView(mp);
    mp = null;
}

Does anyone have any thoughts on what the reference I am neglecting to destroy here?

  • 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-05-27T06:30:50+00:00Added an answer on May 27, 2026 at 6:30 am

    I encountered the same issue. Here is how I solved it :

    • As it should be only one instance of the mapView in the activity, I initialize it in onCreate method in Activity :

      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // initialize MapView programmatically to be used in Fragment :
          this.mActivityMapView = new MapView(MainActivity.this, getString(R.string.debug_mapview_apikey));
      
          setContentView(R.layout.activity_main);
      }
      
    • Then I recover it in the fragment onCreateView method :

      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          this.mMapView = ((MainActivity) getActivity()).getMapView();
          return this.mMapView;
      }
      
    • And I destroy it in the fragment onDestroy method :

      public void onDestroy() {
          NoSaveStateFrameLayout parentView = (NoSaveStateFrameLayout) this.mMapView.getParent();
          parentView.removeView(this.mMapView);
          super.onDestroy();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Me used Fragment of Android Compatibility Package, using the android-support-v4.jar . But I can't
I'm currently using a CursorLoader inside a Fragment with the Android Compatibility Library. Almost
My app is currently using the Fragments/v4 compatibility package to support Android versions all
I'm building an application using a service and the fragment compatibility pack and am
First things first, I'm using the compatibility library and here's the error I'm getting:
Using Android, here is part of a layout xml file: <LinearLayout android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=vertical
I wanna ask guide about android application Compatibility,I am developing an application using Android
I am using android compatibility library, and I am having some problems with listfragments
I'm using the Android Compatibility library to implement fragments and have extended the layout
I'm using fragments in my Android application using the compatibility package. I have tested

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.