I have a layout which I populate with two fragments. I have written a service that fetches data online and then repopulate the layout with two fragments . I want to destroy old fragments and then place the new one but this keeps on adding the new fragments in the layout. If I use beginTransaction().replace that only adds one fragment at a time in layout . How can I achieve this thing?

new Handler().post(new Runnable() {
            public void run() {         

                Fragment f = getFragmentManager().findFragmentByTag("fragmentNowPlaying");
                if (f != null)

                f = getFragmentManager().findFragmentByTag("fragmentChannel");
                if (f != null)

                FragmentTransaction transaction = fm.beginTransaction();
                FragmentNowPlaying fragmentNowPlaying = new FragmentNowPlaying();
                transaction = fm.beginTransaction().add(R.id.content,fragmentNowPlaying, "fragmentNowPlaying");

                transaction = fm.beginTransaction();
                FragmentChannel fragmentchannel = new FragmentChannel();
                transaction = fm.beginTransaction().add(R.id.content,fragmentchannel, "fragmentChannel");

Related posts

Recent Viewed