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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:44:26+00:00 2026-06-14T13:44:26+00:00

So I am working on a project I want to run on legacy Android

  • 0

So I am working on a project I want to run on legacy Android devices so I am using the compatibility library. I am using an interface similar to NewsReader, only instead of the two fragments being in the Activity, they are embedded in another Fragment, which is embedded in a ViewPagger.

For simplicity we will use these terms…

Activity -> ViewPager -> ContainerFragment->Fragment1
                                          ->Fragment2

In ContainerFragment I am trying to replace out fragment 1 with fragment 2 if it is a phone so I tried the following code in ContainerFragment…

import android.support.v4.app.FragmentTransaction;    
...
public void onBarSelected(Integer index) {
    selectedBarIndex = index;
    if (isDualPane) {
        // display it on the article fragment
        mBarEditFragment.displayBar(index);
    }
    else {
        // use separate activity
        FragmentActivity activity = (FragmentActivity)getActivity();
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        ft.replace(R.id.bar_container, new BarEditFragment(),R.id.bar_edit);
    }

}

But I get the following compile error

Type mismatch: cannot convert from android.app.FragmentTransaction 
 to android.support.v4.app.FragmentTransaction

I double checked and the activity does extend the compatibility FragmentActivity.

UPDATE

Tried to change to…

and got….

MainActivity activity = (MainActivity)getActivity();
Object test = activity.getFragmentManager().beginTransaction();
FragmentTransaction ft = (FragmentTransaction)test;
ft.replace(R.id.bar_container, new BarEditFragment());

And I got…

java.lang.ClassCastException: android.app.BackStackRecord cannot be cast to android.support.v4.app.FragmentTransaction

Any ideas?

ANSWER:

I figured out my problem The issue is you shouldn’t get the Fragment manager from the Activity and should get it from the fragment instead.

This works….

public void onBarSelected(Integer index) {
    selectedBarIndex = index;
    if (isDualPane) {
        // display it on the article fragment
        //mBarEditFragment.displayBar(index);
    }
    else {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.bar_container, new BarEditFragment());
        ft.commit();
    }

}
  • 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-14T13:44:27+00:00Added an answer on June 14, 2026 at 1:44 pm

    Facing same problem solved using

    getSupportFragmentManager()

    Thanks

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

Sidebar

Related Questions

i always working in android mobile devices. i want to run my projects in
I'm working on a project and we want to handle our logging using log4j.
I am currently working on android project where I want to have a text
i am working on project using play 2 framework with java. I want to
I'm working on a project using C++. I want a TimerHandler to be called
In Short: I am working on a project and I want to run a
I have a working Android tuner project app that I want to use as
I am working on project where I want to show UIActionsheet with three buttons
I am working with UIWebView project and I want to load an HTML file
I am working on blackberry project where i want to download image & save

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.