Some drawables cannot be found

After I had added some more vector drawables, I noticed that some of the previous ones are not working (about 11). With the rest of them I don’t have any problems – they are shown properly. I link every drawable in Java class with method like image.setImageResource(R.drawable.path_to_image); and most of them are linked without any problems. I have such a problem with just a few ones.
After running an app and trying to show these drawables I got such error:

Unable to find resource: 2131099763
android.content.res.Resources$NotFoundException: Drawable com.example.example_app:drawable/f_user_achievements_learning1h with resource ID #0x7f060073
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/f_user_achievements_learning1h.xml from drawable resource ID #0x7f060073
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
    at android.content.res.Resources.getDrawable(Resources.java:767)
    at android.content.Context.getDrawable(Context.java:525)
    at android.widget.ImageView.resolveUri(ImageView.java:840)
    at android.widget.ImageView.onMeasure(ImageView.java:982)
    at android.view.View.measure(View.java:19734)
    at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:222)
    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117)
    at android.widget.TableRow.onMeasure(TableRow.java:113)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.forceUniformWidth(LinearLayout.java:1000)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:980)
    at android.widget.TableLayout.measureVertical(TableLayout.java:473)
    at android.widget.TableLayout.onMeasure(TableLayout.java:436)
    at android.view.View.measure(View.java:19734)
    at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1293)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.widget.ScrollView.onMeasure(ScrollView.java:340)
    at android.view.View.measure(View.java:19734)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:676)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:479)
    at android.view.View.measure(View.java:19734)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:676)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:479)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:671)
    at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1319)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:736)
    at android.view.View.measure(View.java:19734)
    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
    at android.view.Choreographer.doCallbacks(Choreographer.java:683)
    at android.view.Choreographer.doFrame(Choreographer.java:619)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
 Caused by: java.lang.IllegalArgumentException: Path string cannot be empty.
    at android.util.PathParser.nCreatePathDataFromString(Native Method)
    at android.util.PathParser.-wrap1(PathParser.java)
    at android.util.PathParser$PathData.<init>(PathParser.java:74)
    at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1556)
    at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1507)
    at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:693)
    at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:598)
    at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
        ... 74 more

This is the fragment of Java class, where I link drawable:

@Override
    protected void setChoiceState() {
        if(achievement.isAchieved()) {
            image.setAlpha(ITEM_CHOSEN);
            image.setImageResource(achievement.getResId());
        } else {
            image.setAlpha(ITEM_NOT_CHOSEN);
            image.setImageResource(R.drawable.f_user_achievements_not_achieved);
        }
    }

Where achievement.getResId() is path to drawable. I’ve also tried to change it to raw path like R.drawable.path_to_drawable but it also didn’t work. However, line with: image.setImageResource(R.drawable.f_user_achievements_not_achieved); is working properly.

Here are my .gradle files:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.2'

    defaultConfig {
        applicationId "com.example.example_app"
        vectorDrawables.useSupportLibrary = true
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "2g"
    }
}

repositories {
    maven {
        url "https://maven.google.com"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/gson-2.8.0.jar')
    compile files('libs/commons-lang-2.3.jar')
    compile files('libs/httpclient-4.5.3.jar')
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.google.android.gms:play-services-ads:11.6.2'
    compile 'com.google.android.gms:play-services-auth:11.6.2'
    compile 'com.android.support:multidex:1.0.0'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

If you need any other files, just write a comment and I’ll attach them

EDIT

I added two extra drawables (both Vector Assets) – one which hadn’t been working and the other one with which there hadn’t been any problems. First one is not working but the seconds one is working properly, so can be problem with just xml file representing vector drawable?

Here is an xml file for one of not working vector drawables:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.000002"
        android:viewportHeight="24.000002">
    <path
        android:pathData="M12,12m-11.803,0a11.803,11.803 0,1 1,23.605 0a11.803,11.803 0,1 1,-23.605 0"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffffff"
        android:fillColor="#1b1b1b"
        android:strokeWidth="0.40124387"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.02,15.376 l0,-1.975c0,-0.821 1.742,-1.929 1.742,-1.929l0,-0.662c0,0 -1.742,-1.031 -1.742,-1.852l0,-1.975"
        android:strokeLineCap="round"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="1.03580773"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m12.623,15.376 l0,-1.975c0,-0.821 -1.742,-1.929 -1.742,-1.929l0,-0.662c0,0 1.742,-1.031 1.742,-1.852l0,-1.975"
        android:strokeLineCap="round"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="1.03580773"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M7.18,5.604L13.463,5.604A0.295,0.295 117.507,0 1,13.759 5.9L13.759,6.087A0.295,0.295 0,0 1,13.463 6.382L7.18,6.382A0.295,0.295 0,0 1,6.885 6.087L6.885,5.9A0.295,0.295 117.507,0 1,7.18 5.604z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"
        android:strokeWidth="0.39954987"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M7.18,15.977L13.463,15.977A0.295,0.295 0,0 1,13.759 16.273L13.759,16.459A0.295,0.295 0,0 1,13.463 16.755L7.18,16.755A0.295,0.295 0,0 1,6.885 16.459L6.885,16.273A0.295,0.295 0,0 1,7.18 15.977z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"
        android:strokeWidth="0.39954987"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.853,15.506 l2.937,0 -1.43,-0.988z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffb3cc"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.43446419"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.909,8.698 l2.804,0c0.314,0.066 -0.754,1.004 -1.399,1.366C9.655,9.709 8.665,8.784 8.909,8.698Z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffb3cc"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.40527168"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m-21.276,14.911c0.008,0.022 0.418,1.042 0.911,2.265 0.49,1.223 0.9,2.24 0.905,2.256 0.019,0.049 0.873,0.049 0.892,0.003 0.006,-0.019 0.416,-1.037 0.905,-2.259 0.492,-1.223 0.903,-2.243 0.911,-2.265 0.014,-0.033 -0.046,-0.038 -0.418,-0.033l-0.432,0.008 -0.7,1.701c-0.383,0.935 -0.703,1.701 -0.711,1.701 -0.008,0 -0.328,-0.766 -0.711,-1.701l-0.7,-1.701 -0.432,-0.008c-0.372,-0.006 -0.432,0 -0.418,0.033z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"/>
    <path
        android:pathData=""
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.84933162"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M17.063,16.438m-2.344,0a2.344,2.344 0,1 1,4.689 0a2.344,2.344 0,1 1,-4.689 0"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="0.43581513"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m16.973,16.438 l0,1.101 0.16,0 0.161,0 0.004,-0.492 0.004,-0.491 0.036,-0.078c0.072,-0.156 0.209,-0.238 0.395,-0.238 0.122,0 0.207,0.033 0.266,0.106 0.08,0.098 0.082,0.105 0.087,0.676l0.004,0.517 0.167,0 0.166,0 0,-0.525c0,-0.58 -0.006,-0.653 -0.073,-0.783 -0.181,-0.36 -0.752,-0.396 -0.997,-0.064l-0.056,0.075 0,-0.453 0,-0.453 -0.161,0 -0.161,0 0,1.101z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"/>
    <path
        android:pathData="m15.704,15.553 l0,0.155 0.21,0 0.21,0 0,0.885 0,0.885 0.167,0 0.167,0 0,-1.039 0,-1.039 -0.377,0 -0.377,0 0,0.155z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"/>
</vector>

Solution:

There is a line with an empty path data in the middle of the file. Maybe that’s the culprit (doesn’t look right for sure):

<path
    android:pathData=""
    android:strokeLineCap="round"
    android:fillAlpha="1"
    android:strokeColor="#00000000"
    android:fillColor="#ffb3cc"
    android:strokeWidth="0.84933162"
    android:strokeLineJoin="round"
    android:strokeAlpha="1"/>

Java 8 -Two interfaces contain same 'name' default method but different method signature, how to override?

I understand that if a class implements multiple interfaces containing default methods of same name, then we need to override that method in the child class so as to explicitly define what my method will do.
Problem is, see the below code :

interface A {
    default void print() {
        System.out.println(" In interface A ");
    }
}

interface B {
    default String print() {
        return "In interface B";
    }
}

public class C implements A, B {

    @Override
    public String print() {
        return "In class C";
    }

    public static void main(String arg[]) {
        // Other funny things
    }
}

Now interface A and B both have a default method with name ‘print’ but I want to override the print method of interface B – the one that returns a string and leave A’s print as is. But this code doesn’t compile giving this :

Overrides A.print
The return type is incompatible with A.print()

Clearly compiler is trying to override A’s print method, and I have no idea why !

Solution:

This is not possible.

8.4.8.3:

If a method declaration d1 with return type R1 overrides or hides the declaration of another method d2 with return type R2, then d1 must be return-type-substitutable for d2, or a compile-time error occurs.

8.4.5:

A method declaration d1 with return type R1 is return-type-substitutable for another method d2 with return type R2 iff any of the following is true:

  • If R1 is void then R2 is void.

  • If R1 is a primitive type then R2 is identical to R1.

  • If R1 is a reference type then one of the following is true:

    • R1, adapted to the type parameters of d2, is a subtype of R2.

    • R1 can be converted to a subtype of R2 by unchecked conversion.

    • d1 does not have the same signature as d2, and R1 = |R2|.

In other words, void, primitive- and reference-returning methods may only override and be overridden by methods of that same respective category. A void method may only override another void method, a reference-returning method may only override another reference-returning method, and so on.

One possible solution to the problem you’re having could be to use composition instead of inheritance:

class C {
    private A a = ...;
    private B b = ...;
    public A getA() { return a; }
    public B getB() { return b; }
}

How do you create a generic placeholder function in Java that takes functions as parameters to be used later?

I don’t know how to articulate my question, but it is really simple. I want to create a generic placeholder function that accepts one argument in an already existing function. Let me give you an example. To make things easy, suppose I wanted to know how long it takes for a function to execute in milliseconds.

public class Example{
   public static void main(String[] args) {
      int arr[] = {30, 8, 21, 19, 50, ... , n};
      //needs to accept a function with a parameter as an argument.
      timeTakenFunc(foo(arr), arr);
      timeTakenFunc(bar(arr), arr);
   }

   public static void foo(int A[]){
     //do stuff
   }

   public static void bar(int A[]){
     //do stuff
   } 

   public static void timeTakenFunc(/*what goes here?*/, int A[]){
      long startTime = System.nanoTime();

      //placeholder for foo and bar function here
      placeholder(A);

      long endTime = System.nanoTime();
      long duration = ((endTime - startTime) / 1000000);
      System.out.println("function took: " + duration + "milliseconds");

   }
}

Feel free to edit my question if it needs to be articulated better.

Solution:

Using Java 8 lambdas and functional interfaces, you can accept a Runnable which performs some generic, unspecified action.

public static void timeTakenFunc(Runnable func) {
  long startTime = System.nanoTime();

  //placeholder for foo and bar function here
  func.run();

  long endTime = System.nanoTime();
  long duration = ((endTime - startTime) / 1000000);
  System.out.println("function took: " + duration + "milliseconds");
}

You would then call it like so:

timeTakenFunc(() -> foo(arr));
timeTakenFunc(() -> bar(arr));

This is shorthand for the pre-lambda equivalent of:

timeTakenFunc(new Runnable() {
    @Override public void run() {
        foo(arr);
    }
});
timeTakenFunc(new Runnable() {
    @Override public void run() {
        bar(arr);
    }
});

I removed the int[] A parameter as it’s not necessarily needed here. As you can see, arr can be embedded inside the Runnable. If you wanted to keep it as a parameter then you could switch from Runnable to Consumer<int[]>.

public static void timeTakenFunc(Consumer<int[]> func, int[] A) {
  long startTime = System.nanoTime();

  //placeholder for foo and bar function here
  func.accept(A);

  long endTime = System.nanoTime();
  long duration = ((endTime - startTime) / 1000000);
  System.out.println("function took: " + duration + "milliseconds");
}

timeTakenFunc(arr -> foo(arr), A);
timeTakenFunc(arr -> bar(arr), A);

Or using method references with ::, you can write:

timeTakenFunc(Example::foo, A);
timeTakenFunc(Example::bar, A);

Both of these are equivalent to this pre-lambda code:

timeTakenFunc(new Consumer<int[]>() {
    @Override public void accept(int[] arr) {
        foo(arr);
    }
});
timeTakenFunc(new Consumer<int[]>() {
    @Override public void accept(int[] arr) {
        bar(arr);
    }
});

Listen DialogFragment dismiss event from ViewPager Fragment

There are lot of (duplicate) questions and answers are available, I went through almost all of them and failed. On reference of this question, I made some changes recently.

Brief : In my app, MainActivity holds Fragment View Pager and FrangmentA,B and C. FrangmentA Shows a DialogFragment CDialog onClik. After dismissing CDialog I need to Call FragmentA’s doReload() which is not happening here.

MainActivity

protected void onCreate(Bundle savedInstanceState){
                          ...

            mSectionsPageAdapter = new FragmentAdapter(getSupportFragmentManager());
            mViewPager = (ViewPager) findViewById(R.id.container);
            setupViewPager(mViewPager);
            TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
            tabLayout.setupWithViewPager(mViewPager);
            int defaultValue = 0;
            int page = getIntent().getIntExtra("One", defaultValue);
            mViewPager.setCurrentItem(page);
    }

    private void setupViewPager(ViewPager viewPager)
        {
            FragmentAdapter adapter = new 
            FragmentAdapter(getSupportFragmentManager());
            adapter.addFragment(new FragmentA(), "FragA");
            adapter.addFragment(new FragmentB(), "FragB");
            adapter.addFragment(new FragmentC(), "FragC");
            viewPager.setAdapter(adapter);
        }

FragmentA

    public class FragmentA extends Fragment implements CDialog.Dismissed{
    @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    ...
    button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                   FragmentManager fm =  getActivity().getFragmentManager();
                    DialogFragment f = new CDialog();
                    f.show(fm, "CDialog");
                    }
            });

 @Override
    public void dialogDismissed() {
        Log.e(DFD_1, "dialogDismiss Called" );// <-- This is not working*
        doReload();
    }
    }

And CDialogue

public  class CDialog extends DialogFragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
                                    ....
                      return v;
   }
  @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
           ...

            dfd_1.setOnClickListener(
            new View.OnClickListener() {
                public void onClick(View v) {
                        getDialog().dismiss(); //<--when this happens*
                    }
            });

}
    @Override
        public void onDismiss(DialogInterface dialog) {
            if (getActivity() != null && getActivity() instanceof Dismissed) {
                ((Dismissed) getActivity()).dialogDismissed();
            }
            super.onDismiss(dialog);
        }

        public interface Dismissed {
            public void dialogDismissed();  //<-- FragmentA implements this 
        }
}

Solution:

You can always have direct callback to your Fragment itself.

First step, is to set targetFragment using setTargetFragment():

DialogFragment#setTargetFragment(Fragment fragment, int requestCode);

I do it this way:

public void showDialogFragment(Fragment targetFragment, AppCompatDialogFragment appCompatDialogFragment, int requestCode) {
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    appCompatDialogFragment.setTargetFragment(targetFragment, requestCode);
    fragmentTransaction.add(appCompatDialogFragment, appCompatDialogFragment.getClass().getSimpleName());
    fragmentTransaction.commitAllowingStateLoss();
}

and then call to this method to open dialog fragment as:

public static final int RC_CDIALOG = 111;

button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
               showDialogFragment(FragmentA.this, new CDialog(), RC_CDIALOG);
            }
        });

Then, in your DialogFragment’s onDismissListener(), have some code like below:

@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);

    if (getTargetFragment() instanceof FragmentA)
        ((FragmentA) getTargetFragment()).doReload();

}

What you did this way is:

Show Dialog Fragment “CDialog” along with telling it that your target fragment is “FragmentA” whose reference you can use incase you have something to do with it. In your case you had to call doReload();