2

When I call fragment from activity then fragment calling successfully but some part of previous activity is on the top of in fragment, anyone help to correct the code

package com.example.newproject;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import static android.view.View.GONE;

public class ThankYouPageActivity extends AppCompatActivity {
    Button thank_continue_btn,thank_track_btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_thank_you_page);
        getSupportActionBar().setTitle("Confirmation");


        thank_continue_btn = findViewById(R.id.thank_continue_btn);
        thank_track_btn = findViewById(R.id.thank_track_btn);




        findViewById(R.id.thank_continue_btn).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {

               FragmentManager fm = getSupportFragmentManager();
               HomeFragment fragment = new HomeFragment();
               fm.beginTransaction().replace(R.id.thanku_container, fragment).addToBackStack(null).commit();
Aman kumar
  • 21
  • 5
  • 1
    Can you share xml of activity and fragment – Kishan Maurya Oct 02 '19 at 09:23
  • Possible duplicate of [Caused by: java.lang.IllegalStateException: Unable to create directory in Android 6.0 devices](https://stackoverflow.com/questions/35767923/caused-by-java-lang-illegalstateexception-unable-to-create-directory-in-androi) – majid ghafouri Oct 02 '19 at 09:39
  • The fragment layout has a transparent background. You should add a suitable background color for the fragment layout. – Sagar Chapagain Oct 02 '19 at 09:49

4 Answers4

0

set background to white in the root tag of your fragment's xml

background = "#FFFFFF"
Mehul Pamale
  • 349
  • 3
  • 13
0

The container of your Fragment must be overlapped by your Activity layouts. Please attach the layouts of your Activity and Fragment so that I can help you find your issue.

Vikas
  • 136
  • 6
0

I had same issues , i fixed it by removing previous fragment while setting new fragment in oncreateview

container.removeAllViews(); before replacing the fragment

  • container.removeAllViews(); is give error in my activity – Aman kumar Oct 02 '19 at 10:31
  • can u post a picture and what is it showing , previous fragment content or activity content where you have framelayout ? Also u dont use this code in activity you use this in your fragment class in oncreateview – babin tandukar Oct 03 '19 at 11:16
-1

R.id.thanku_container - I think it is FrameLayout?

Make it full match_parent. Or set background color like activity.

Tasos K.
  • 7,979
  • 7
  • 39
  • 63