Fragment with googlemaps: inflater.inflate crashes when destoried and recreated in ViewPager?

I am using actionbarsherlock and its sherlockFragmentActivity.

I have 3 fragments and in a Tab + ViewPager layout.

The 3rd fragment is the problem. It is a fragment that displays my location on a google maps.

From what I notice, viewpager, will CREATE the new page, and if we scroll away from a page for more than 1 page, then it will DESTORY that page.

So its all fine the first time around, i go to page 2, and it calls CREATE on page3 with GOOGLEMAPS.

HOWEVER, the problem is if i go back to page 1 (DESTORIES page 3 googlemaps). Now if i go back to page 2 (tries to create page3), page3's inflater.inflate will DIE and i'll get an error, first is the Choreographer class.

So my question is, WHY IS inflater.inflate failing, and WHAT IS THE PROPER way to program tab viewpager with fragments like this.???

Code here (ON create of main activity):

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main_activity);
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();

        mViewPager = (ViewPager)findViewById(R.id.pager);

        mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

        mTabsAdapter.addTab(mTabHost.newTabSpec("driverInfo").setIndicator("Driver Info"),
                DriverInfo.class, null);
        mTabsAdapter.addTab(mTabHost.newTabSpec("alarmSystem").setIndicator("Alarm System"),
                AlarmSetting.class, null);
        mTabsAdapter.addTab(mTabHost.newTabSpec("vehicleLocation").setIndicator("Location"),
                VehicleLocation.class, null);


        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("tab", mTabHost.getCurrentTabTag());
    }

Code: Location Fragment:

public class VehicleLocation extends Fragment implements ServerRequestInterface {

    private GoogleMap mMap; 
    private ProgressDialog mProgressDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        try
        {
            super.onCreate(savedInstanceState);
            setupProgressDialog();
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }


}

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//WHere it keeps die-ing     ----------------------------------    
    View view = inflater.inflate(R.layout.vehicle_location, container, false);
            setUpMapIfNeeded();
            return view;
        }

Error Log:

05-13 20:48:31.532: E/AndroidRuntime(13219): FATAL EXCEPTION: main
05-13 20:48:31.532: E/AndroidRuntime(13219): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.covixon.main.VehicleLocation.onCreateView(VehicleLocation.java:37)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.view.ViewPager$3.run(ViewPager.java:238)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer.doFrame(Choreographer.java:531)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Handler.handleCallback(Handler.java:725)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.os.Looper.loop(Looper.java:137)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.app.ActivityThread.main(ActivityThread.java:5237)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at java.lang.reflect.Method.invokeNative(Native Method)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at java.lang.reflect.Method.invoke(Method.java:511)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at dalvik.system.NativeStart.main(Native Method)
05-13 20:48:31.532: E/AndroidRuntime(13219): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040066, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
05-13 20:48:31.532: E/AndroidRuntime(13219):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-13 20:48:31.532: E/AndroidRuntime(13219):    ... 26 more

Answers


After staring at the stack trace more, i noticed the line

 Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040066, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment

which lead me to google this like, which solved my issue:

Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment


Need Your Help

Facebook like button doesn't work anymore

facebook like

Sometime ago I made a like button for my website with the help of this tool: http://developers.facebook.com/docs/reference/plugins/like/ and it worked well, the visitor could like the page and also...

Facebook's 5000 Post API Limit

php facebook facebook-graph-api

I have a question about the way Facebook limits your api calls.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.