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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:20:30+00:00 2026-06-15T04:20:30+00:00

Into my project I am using viewpager with three tabs named History , Main

  • 0

Into my project I am using viewpager with three tabs named History,Main,Map.Main activity contain Timer,stopwatch,etc. Map display the google map. and into History right now I am using only simple Textview.

Viewpager flow direction : History – Main – Map

I set the Main as the current item(Bydefault Main tag display).Now when I am swipe from Main > Map and Map > Main its working perfect. but when swipe from Main > History there is no error but back return from History to Main( History > Main) eclipse give me error like :

E/AndroidRuntime(  533): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

And FYI I am using intent into Map Activity.Please check below code.Please let me know how can solve my problem.

ViewPager class:

@Override
    public Fragment getItem(int position) {
        // return SwipeyTabFragment.newInstance(TITLES[position]);

        Fragment f = new Fragment();

        switch (position) {
        case 0:
            f = History.newInstance(position);
            break;
        case 1:
            f = Main.newInstance(position);
            break;
        case 2:
            f = Map.newInstance(position);
            break;

        }

        return f;

    }

History.class:

public class History extends Fragment {

public static Fragment newInstance(int position) {
    History f = new History();
    Bundle args = new Bundle();

    args.putInt("title", position);
    f.setArguments(args);
    return f;

}

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.history, null);


     ( (TextView) root.findViewById(R.id.text)).setText("Hello");
    return root;
} 

}

Main.class :

 public class Main extends Fragment implements GPSCallback {

 ......

public static Fragment newInstance(int position) {
    Main f = new Main();
    Bundle args = new Bundle();

    args.putInt("title", position);
    f.setArguments(args);
    return f;

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    final ViewGroup root = (ViewGroup) inflater
            .inflate(R.layout.main, null);

    .......

    return root;
 }

    ........
}

Map.class :

public class Map extends Fragment {

private static final String KEY_STATE_BUNDLE = "localActivityManagerState";

private LocalActivityManager mLocalActivityManager;

protected LocalActivityManager getLocalActivityManager() {
    return mLocalActivityManager;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle state = null;
    if (savedInstanceState != null) {
        state = savedInstanceState.getBundle(KEY_STATE_BUNDLE);
    }

    mLocalActivityManager = new LocalActivityManager(getActivity(), true);
    mLocalActivityManager.dispatchCreate(state);
}



public static Fragment newInstance(int position) {
    Map f = new Map();
    Bundle args = new Bundle();

    args.putInt("title", position);
    f.setArguments(args);
    return f;

}


  @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

        Intent i = new Intent(getActivity(), MapViewActivity.class);
       // Intent i = new Intent(getActivity(), hellogooglemap.class);
        Window w = mLocalActivityManager.startActivity("tag", i); 

        View currentView=w.getDecorView(); 
        currentView.setVisibility(View.VISIBLE); 
        currentView.setFocusableInTouchMode(true); 
        ((ViewGroup) currentView).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        return currentView;


      /*ViewGroup root = (ViewGroup) inflater.inflate(R.layout.history, null);


         ( (TextView) root.findViewById(R.id.text)).setText("Hello");
        return root;*/

}


 @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBundle(KEY_STATE_BUNDLE,
                mLocalActivityManager.saveInstanceState());
    }

    @Override
    public void onResume() {
        super.onResume();
        mLocalActivityManager.dispatchResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mLocalActivityManager.dispatchPause(getActivity().isFinishing());
    }

    @Override
    public void onStop() {
        super.onStop();
        mLocalActivityManager.dispatchStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mLocalActivityManager.dispatchDestroy(getActivity().isFinishing());
    }

}

Logcat :

 E/AndroidRuntime(  533): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
 E/AndroidRuntime(  533):   at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.addView(ViewGroup.java:1871)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.addView(ViewGroup.java:1828)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.addView(ViewGroup.java:1808)
 E/AndroidRuntime(  533):   at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
 E/AndroidRuntime(  533):   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:874)
 E/AndroidRuntime(  533):   at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1240)
 E/AndroidRuntime(  533):   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:612)
 E/AndroidRuntime(  533):   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
 E/AndroidRuntime(  533):   at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
 E/AndroidRuntime(  533):   at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:139)
 E/AndroidRuntime(  533):   at android.support.v4.view.ViewPager.populate(ViewPager.java:804)
 E/AndroidRuntime(  533):   at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1280)
 E/AndroidRuntime(  533):   at android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1176)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.drawChild(ViewGroup.java:1562)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
 E/AndroidRuntime(  533):   at android.view.View.draw(View.java:6883)
 E/AndroidRuntime(  533):   at android.widget.FrameLayout.draw(FrameLayout.java:357)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
 E/AndroidRuntime(  533):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
 E/AndroidRuntime(  533):   at android.view.View.draw(View.java:6883)
 E/AndroidRuntime(  533):   at android.widget.FrameLayout.draw(FrameLayout.java:357)
 E/AndroidRuntime(  533):   at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
 E/AndroidRuntime(  533):   at android.view.ViewRoot.draw(ViewRoot.java:1522)
 E/AndroidRuntime(  533):   at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
 E/AndroidRuntime(  533):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
 E/AndroidRuntime(  533):   at android.os.Handler.dispatchMessage(Handler.java:99)
 E/AndroidRuntime(  533):   at android.os.Looper.loop(Looper.java:130)
 E/AndroidRuntime(  533):   at android.app.ActivityThread.main(ActivityThread.java:3683)
 E/AndroidRuntime(  533):   at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(  533):   at java.lang.reflect.Method.invoke(Method.java:507)
 E/AndroidRuntime(  533):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 E/AndroidRuntime(  533):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 E/AndroidRuntime(  533):   at dalvik.system.NativeStart.main(Native Method)
 W/ActivityManager(   68):   Force finishing activity      com.android.gps/.viewpager.SwipeyTabsSampleActivity
 W/ActivityManager(   68): Activity pause timeout for HistoryRecord{40716740 com.android.gps/.viewpager.SwipeyTabsSampleActivity}

Thanks.

EDIT:

Without intent into Map activity it works pwrfect.I mean when i am using same as history into map there is no any error.

  • 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-15T04:20:31+00:00Added an answer on June 15, 2026 at 4:20 am

    I have also faced this problem.

    You can solve it by just add single line mViewPager.setOffscreenPageLimit(3);

    public class SwipeyTabsSampleActivity extends FragmentActivity {
    
    ...
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.main);
    
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);
    
        SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this,
                getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
    
        mViewPager.setOffscreenPageLimit(3);  <------  Add this one
    }
    
    }
    

    Good Luck.

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

Sidebar

Related Questions

I've walked into a project that is using a WCF service for the data
I successfully created a project using Wicket quickstart and turned it into an Eclipse
I'm using seeds.rb to load some dummy data into my project as I develop
Earlier to deploy my dot-net project into my remote server I was using copy
I am using mongoDB for a new project at work and I got into
I am looking into using Google App Engine for a project and would like
I'm looking into using parallel unit tests for our project(s) and was wondering about
I'm currently looking into using WIF for an upcoming project and would appreciate some
We are using Doctrine 2 for a new project and have run into an
I'm not using the default Visual Studio project path to build my program into,

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.