启用导航按钮后,应用程序完全冻结

时间:2018-12-09 09:49:12

标签: android android-fragments android-viewpager

在我的应用中是BottomAppBar,它允许用户在不同的片段之间导航。几天前,我注意到我的应用程序完全冻结,没有错误消息,即使我在类中没有更改任何一行,但应显示某个片段。今天,我禁用了模拟器的config.ini文件中的导航按钮,以制作一些屏幕截图。然后,我无意中单击了无法正常工作的片段的导航条目,然后突然再次正常工作。但是,一旦我再次启用这些按钮,它就会停止工作。它也不能在其他模拟器上使用。

我将模拟器的配置文件中的以下行从yes更改为no以禁用按钮:

hw.mainKeys=no
hw.keyboard=no

无效片段的类别:

private TabLayout mTabLayout;
private ViewPager mViewPager;

private BankAccountsStatisticsFragment bankAccountsStatisticsFragment;
private BillsStatisticsFragment billsStatisticsFragment;
private CategoriesStatisticsFragment categoriesStatisticsFragment;
private GoalsStatisticsFragment goalsStatisticsFragment;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View inflatedView = inflater.inflate(R.layout.fragment_statistics, container, false);

    setupFragments();

    mTabLayout = (TabLayout) inflatedView.findViewById(R.id.tl_statistics);
    mViewPager = (ViewPager) inflatedView.findViewById(R.id.vp_statistics);

    mViewPager.setAdapter(new Adapter(getChildFragmentManager()));
    mTabLayout.setupWithViewPager(mViewPager);

    return inflatedView;
}

private class Adapter extends FragmentPagerAdapter {

    private static final int TABS = 4;

    public Adapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0:return bankAccountsStatisticsFragment;
            case 1: return billsStatisticsFragment;
            case 2: return categoriesStatisticsFragment;
            case 3: return goalsStatisticsFragment;
            default: throw new IllegalStateException("Couldn't find a fragment for position " + position);
        }
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position){
            case 0: return getString(R.string.tab_bank_accounts);
            case 1: return getString(R.string.tab_bills);
            case 2: return getString(R.string.tab_categories);
            default: return getString(R.string.tab_goals);
        }
    }

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

private void setupFragments(){
    bankAccountsStatisticsFragment = new BankAccountsStatisticsFragment();
    billsStatisticsFragment = new BillsStatisticsFragment();
    categoriesStatisticsFragment = new CategoriesStatisticsFragment();
    goalsStatisticsFragment = new GoalsStatisticsFragment();
}

ViewPager的片段似乎不起作用,因为从应用程序的另一部分返回不同的片段时,它可以正常工作。

冻结时的LOGCAT

  

12-09 09:42:18.786 1564-3126 /? W / audio_hw_generic:未向HAL提供足够的数据,预期位置1027726,仅写入1027440   12-09 09:42:21.540 1814-1828 / system_process E / memtrack:无法加载memtrack模块   12-09 09:42:21.540 1814-1828 / system_process W / android.os.Debug:无法获取内存消耗信息:-1   12-09 09:42:21.998 1564-1643 /? W / audio_hw_generic:没有向HAL提供足够的数据,预期位置1338681,仅写入1181520   12-09 09:42:36.339 2514-5023 / com.google.android.gms I / ufd:18-ClearListeners-元数据{强制:true,service_id:0}   12-09 09:42:40.693 1814-1828 / system_process E / memtrack:无法加载memtrack模块

0 个答案:

没有答案