onResume() not called on ViewPager fragment when using custom Loader

后端 未结 2 2073
借酒劲吻你
借酒劲吻你 2021-02-06 12:22

Short version:

I have a fragment that maintains a ViewPager for displaying two other fragments, let\'s call them FragmentOne a

相关标签:
2条回答
  • 2021-02-06 13:06

    It appears to be a bug in support library. The change below solves the issue.

    // FragmentOne.java
    
    @Override
    public void onResume() {
        super.onResume();
        Handler handler = getActivity().getWindow().getDecorView().getHandler();
        handler.post(new Runnable() {
            @Override public void run() {
                // initialize the loader here!
                getLoaderManager().initLoader(0, null, FragmentOne.this);
            }
        });
    }
    
    0 讨论(0)
  • 2021-02-06 13:25

    Another workaround that worked for me was to use the MainFragment's loader manager:

    getParentFragment().getLoaderManager().initLoader(0, null, this);
    
    0 讨论(0)
提交回复
热议问题