从BackStack恢复应用程序或从Notification调用应用程序时,片段变得无响应

时间:2018-10-03 14:16:02

标签: android performance android-fragments

在Dashboard Activity中,顶部有一个Fragment,其中包含3个片段作为视图分页器。在以下情况下,视图分页器变为空白且无响应(如第二张屏幕截图所示):

  1. 从后台加载应用程序时
  2. 当应用程序在后台运行且更改了字体设置并再次从应用程序堆栈中调用时
  3. 单击我的应用程序的通知,并且单击操作重定向到仪表板活动 Screenshot:when activity is created

Screenshot when its notification is clicked and then redirected to this activity

“选项卡的片段”的代码为:

public class MainActivityGraphViewPager extends Fragment {


public MainActivityGraphViewPager() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_main_activity_graph_pager, container, false);
    ViewPager viewPager = v.findViewById(R.id.fgraph_pager);

    TabLayout tabx = v.findViewById(R.id.tab_layout_dashboard);
    tabx.setupWithViewPager(viewPager, true);

    viewPager.setAdapter(new SectionPagerAdapterFeaturedgraphs(getActivity().getSupportFragmentManager()));
    viewPager.setCurrentItem(1, false);
    viewPager.setOffscreenPageLimit(3);
    return v;
}


private class SectionPagerAdapterFeaturedgraphs extends FragmentPagerAdapter {
    public SectionPagerAdapterFeaturedgraphs(FragmentManager supportFragmentManager) {
        super(supportFragmentManager);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return new ExpenseManagerPieChart();

            case 1:
                return new BudgetandFitness();

            case 2:
                return new ExpendsFragments();
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        return 3;
    }
}}

在Dashboard Activity的onCreate()中调用MainActivityGraphViewPager.class:

        MainActivityGraphViewPager mainActivityGraphPager=new MainActivityGraphViewPager();
    this.getSupportFragmentManager().beginTransaction().replace(R.id.graph_pagers, mainActivityGraphPager).commit();

消除这种无反应性的可能解决方案是什么?

0 个答案:

没有答案