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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:32:06+00:00 2026-06-11T05:32:06+00:00

orientation change between different layouts for landscape and portrait seems to be easy, however

  • 0

orientation change between different layouts for landscape and portrait seems to be easy, however I cannot find a solution for my current situation.

I want to use a dual-pane layout with two fragments in landscape mode

res\layout-land\dashboard_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <fragment class="xxx.DashboardFragment"
            android:id="@+id/master_frag"
            android:layout_width="@dimen/timeline_size"
            android:layout_height="match_parent"/>

    <fragment class="xxx.TaskInstanceFragment"
            android:id="@+id/details_frag"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

and a single-pane layout in portrait mode

res\layout\dashboard_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment class="xxx.DashboardFragment"
        android:id="@+id/master_frag"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</FrameLayout>

I want to note that the DashboardFragment consists of a ViewPager. Do not know if it is of importance.

Now, when I change the orientation from landscape (dual) to portrait (single) the app crashes, because it wants to update the details_frag. When I start the activity in portrait, it works, only switching from landscape to portrait makes problems.

In the activity there is the following code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dashboard_activity);

    Fragment frag = getSupportFragmentManager().findFragmentById(R.id.details_frag);
    mDualFragments = frag != null;

    /* .. */
}

Now the FragmentManager still finds the details fragment when I switch to portrait mode and thus mDualFragments is still true but should be false, which leads to a later call to a method in the details fragment.

So, why is this? 🙂

Regards,
Konsumierer

  • 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-11T05:32:08+00:00Added an answer on June 11, 2026 at 5:32 am

    Because findFragmentById not only returns the fragment in the current layout, but also previously displayed fragments. Try this instead:

    mDualFragments = frag != null && frag.isInLayout();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Android, when the screen orientation changes (between landscape and portrait) the onCreate method
I found that when we change the orientation of current activity by screen rotation,
I'm trying to get my app to change layouts when the orientation changes. This
When a user moves their iPhone, my views switch appropriately between portrait and landscape
Am trying to change the button frame according to the orientation change but button
I need to detect android device orientation change without playing manually with sensor data,
What is the correct way to handle an orientation change when using Fragments? I
I'm new to android my question is, Is it possible to change orientation programmatically?
I am trying to change the orientation of a single UIViewController programmatically. The user
I want to prevent my activity from restarting when I change the orientation from

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.