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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:13:08+00:00 2026-06-09T01:13:08+00:00

I know figure 2 of http://developer.android.com/guide/components/fragments.html I wonder what happens from Fragment Active when

  • 0

I know figure 2 of http://developer.android.com/guide/components/fragments.html I wonder what happens from “Fragment Active” when I rotate the screen and eventually be back in “Fragment Active”.

Background of my question is that I have an app which works fine regardless if I start it in portrait or landscape mode. But on screen rotation it dumps

Fragment com.bla.bla did not create a view.

This fragment has basically only onCreateView implemented, nothing else

public View onCreateView(LayoutInflater i, ViewGroup c, Bundle s)
{
   return i.inflate(R.layout.mylayout, c, false);
}

Knowing what exactly happens on screen rotation I hope to solve the issue…

EDIT:

I tried what the commenter suggested, some more information on that. So they all basically suggest to have an empty activity layout and add the fragments programmatically if I see that correctly. I have a main.xml for portrait and one for landscape, both look now very similar (difference is horizontal vs. vertical):

main.xml:

<LinearLayout xmlns:android="http:// and so on" 
    android:layout_width="fill_parent" 
    android:layout_heigt="wrap_content" 
    android:orientation=vertical" 
    android:id="@+id/myContainer">
</LinearLayout>

The onCreate method of my activity looks like this:

super.onCreate(savedInstanceBundle);
setContentView(R.layout.main);

Fragment1 f1 = newFragment1();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.myContainer, f1);
//and I need a second fragment
Fragment2 f2 = newFragment2();
ft.add(R.id.myContainer, f2);
ft.commit();

Screen rotation seems to work with that (so thank you so far!) but in landscape I only see the first fragment in portrait I see both, the second multiple times (the more often I rotate the more often they are added). So either I have a layout issue or I cannot add multiple fragments like this. Still trying to figure if it is a layout issue, but no clue yet. Any hint?

  • 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-09T01:13:10+00:00Added an answer on June 9, 2026 at 1:13 am

    The way I understand you problem, you shouldn’t be adding fragments every time. You should be replacing what’s currently there with your new fragment.

    ft.replace(R.id.myContainer1, f1);
    //and I need a second fragment
    Fragment2 f2 = newFragment2();
    ft.replace(R.id.myContainer2, f2);
    

    As for the Fragment life-cycle – when you rotate the screen, the hosting Activity is destroyed and re-created; so everything right until onDetach() should be called followed by everything starting with onAttach().

    Surest way to know would be to override all the life cycle methods and put in a log message in all of them 🙂

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

Sidebar

Related Questions

I looked at http://developer.android.com/reference/android/view/View.html to figure out the differences but could not understand much.
Quick note: I'm using the SoundPool class http://developer.android.com/reference/android/media/SoundPool.html What I have here is a
I've been following the lessons about transparency and gradients on the Mozilla site: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Applying_styles_and_colors
I'm trying to follow the rails getting started guide http://guides.rubyonrails.org/getting_started.html to create a blog
i am trying to figure out how this software works: http://www.stereopsis.com/flux/ specifically, i would
I'm trying to figure out what happens to an android service when PowerManager.goToSleep() is
I'm trying to figure out how to draw a color map like this: http://www.ritsplasman.com/images/colormap.png
Does anybody know how the Google Interactive Doodles for Olympics work. http://www.google.com/doodles/soccer-2012 I find
http://g.virbcdn.com/_f/cdn_images/resize_1280x640/29/PageImage-489404-2437983-IMG_4531.PNG Hi all, we are trying to figure out how to do the small
I know that I can figure out today's date by [NSDate date]; but how

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.