Android 5.1.1 Недостаточно памяти Фатальный сигнал 11 Ошибка при перелистывании Viewpager Fragmet - PullRequest
0 голосов
/ 20 декабря 2018

В моем приложении для Android я разработал Фрагмент Viewpager , а внутри него Один фрагмент , оба расширяют Фрагмент класс.Приложение работает нормально, но после перелистывания 10-15 страниц вперед или назад оно случайно падает со следующей ошибкой в ​​logcat:

12-20 22:50:21.367: W/ResourceType(21279): Failure getting entry for 0x01080af7 (t=7 e=2807) (error -75)
12-20 22:50:21.747: D/skia(21279): Skia Error: Out Of Memory: (size = 13833300)
12-20 22:50:21.747: A/libc(21279): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 21279 (s.iyykanastaeen)

Сбой происходит только на samsung tablet 5.1.1 не на мобильных телефонах. РЕДАКТИРОВАТЬ Сбой происходит, только если пользовательский шрифт применен с использованием гарнитуры.

try{
        font = Typeface.createFromAsset(tvDuaArabic.getContext().getAssets(), "fonts/arabtype.ttf");  
         ufont = Typeface.createFromAsset(tvDuaUrdu.getContext().getAssets(), "fonts/jameelnoorinastaleeq.ttf");  

    }
    catch (Exception e)
    {
         e.printStackTrace(); 

            // Prints what exception has been thrown 
            System.out.println(e);
    }

    tvDuaArabic.setTypeface(font); 

Пожалуйста, помогите мне решить эту проблему и на планшете.

Вот код из фрагмента Viewpager:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    context = inflater.getContext();
    rootView = (ViewGroup) inflater.inflate(R.layout.fragment_single_dua_view_pager, container, false);
    ga= new GridViewAdapter(context);
            return rootView;

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        ll_back_single_dua_header = (LinearLayout) rootView.findViewById(R.id.ll_back_single_dua_header);
        ll_back_single_dua_footer = (LinearLayout) rootView.findViewById(R.id.ll_back_single_dua_footer);
        tv_back_single_dua_header_title = (TextView) rootView.findViewById(R.id.tv_back_single_dua_header_title);

         ufont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/jameelnoorinastaleeq.ttf"); 

        tv_back_single_dua_footer_counter = (TextView) rootView.findViewById(R.id.tv_back_single_dua_footer_counter);

        togbtnIsFavorite = (ToggleButton) rootView.findViewById(R.id.tog_btn_favorite_dua);
        togbtnRepeat = (ToggleButton) rootView.findViewById(R.id.tog_btn_repeat_dua);
        btnPlayPauseDua = (ImageButton) rootView.findViewById(R.id.btn_play_pause_dua);
        btnShareDua = (ImageButton) rootView.findViewById(R.id.btn_share_dua);
        btn_list_duas = (ImageButton) rootView.findViewById(R.id.btn_list_duas);

        tv_back_single_dua_footer_counter.setText("1/1");



        mPager = (ViewPager) rootView.findViewById(R.id.pager);
    mPagerAdapter = new ScreenSlidePagerAdapter(getChildFragmentManager());
    mPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            mPageNumber = position;
            stopMusicPlayback();
            updateView();

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {}

        @Override
        public void onPageScrollStateChanged(int arg0) {}
    });
    mPager.setAdapter(mPagerAdapter);

        String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
        String[] versesList = verses.split(",");
        int total = versesList.length;
        int position = new SharedPreferencesSupplication().read(SingletonClass.keySelVerseFromList, 0);
        mPager.setCurrentItem((total - 1) - position);
        updateView();

        super.onActivityCreated(savedInstanceState);

    }


    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        repeatDua = false;
        togbtnRepeat.setChecked(false);

        updateView();
        if (new SharedPreferencesSupplication().read(SingletonClass.keyPlayAll, false))
            btnPlayPauseDua.performClick();
        super.onResume();       

    }


    void updateView() {


        mPageNumber = mPager.getCurrentItem();
        String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
        String[] versesList = verses.split(",");
        int index = (versesList.length - 1) - mPageNumber;
        identifier = versesList[index];


        int resID = getActivity().getResources().getIdentifier(identifier, "raw", getActivity().getPackageName());
        try {
            mp = MediaPlayer.create(context, resID);
        }
        catch (Exception e) {
            mp = null;
        }
        btnPlayPauseDua.setBackgroundResource(R.drawable.play_btn_custom);


        tv_back_single_dua_footer_counter.setText((index + 1) + " / " + versesList.length);

    if (new FavoriteDuas().isDuaFavorite(identifier))
            togbtnIsFavorite.setChecked(true);
        else
            togbtnIsFavorite.setChecked(false);

        boolean lang=  new SharedPreferencesSupplication().read(SingletonClass.keylang, false);


        currPos = 0;
    }

    @Override
    public void onPause() {
        new SharedPreferencesSupplication().save(SingletonClass.keyPlayAll, false);
    stopMusicPlayback();
        super.onPause();
    }

    void stopMusicPlayback() {
        if (mp instanceof MediaPlayer) {
            mp.stop();
            mp.release();
        }
        btnPlayPauseDua.setBackgroundResource(R.drawable.play_btn_custom);

    }

private class ScreenSlidePagerAdapter extends FragmentPagerAdapter {

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

        @Override
        public Fragment getItem(int position) {
            return (SingleDuaFragment.create(position));
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
            String[] versesList = verses.split(",");
            return versesList.length;
        }

    }

А вот код из SingleFragment:

public static SingleDuaFragment create(int pageNumber) {
    SingleDuaFragment fragment = new SingleDuaFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_PAGE, pageNumber);
    fragment.setArguments(args);
    return fragment;
}

public SingleDuaFragment() {}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPageNumber = getArguments().getInt(ARG_PAGE);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = inflater.getContext();
rootView = (ViewGroup) inflater.inflate(R.layout.fragment_single_dua, container, false);

tvDuaArabic = (TextView) rootView.findViewById(R.id.tv_arabic);
tvDuaEnglish = (TextView) rootView.findViewById(R.id.tv_english);
tvDuaUrdu = (TextView) rootView.findViewById(R.id.tv_urdu);
tvDuaTranslit = (TextView) rootView.findViewById(R.id.tv_transl);
tvDuaRef = (TextView) rootView.findViewById(R.id.tv_ref);

dividerEng = (TextView) rootView.findViewById(R.id.divider_english);
dividerUrdu = (TextView) rootView.findViewById(R.id.divider_urdu);
dividerTransl = (TextView) rootView.findViewById(R.id.divider_transl);
dividerRef = (TextView) rootView.findViewById(R.id.divider_ref);
        return rootView;
}


@Override
public void onResume() {
    // TODO Auto-generated method stub
    boolean engTransVisible = new SharedPreferencesSupplication().read(SingletonClass.keyEngTrans, true);
    boolean urdTransVisible = new SharedPreferencesSupplication().read(SingletonClass.keyUrdTrans, true);

    String verses = new SharedPreferencesSupplication().read(SingletonClass.keyListOfVerses, "a1");
    String[] versesList = verses.split(",");
    int index = (versesList.length - 1) - mPageNumber;
    String identifier = versesList[index];


    Typeface font = Typeface.createFromAsset(tvDuaArabic.getContext().getAssets(), "fonts/arabtype.ttf"); 


    //Typeface custom_font = Typeface.createFromAsset(tvDuaArabic.getContext().getAssets(), "fonts/Tahoma.ttf");
    tvDuaArabic.setText(SingletonClass.duasAra.get(index));
    //tvDuaArabic.setTypeface(custom_font);
    tvDuaArabic.setTypeface(font); 

    tvDuaEnglish.setText(SingletonClass.duasEng.get(index));

    Typeface ufont = Typeface.createFromAsset(tvDuaUrdu.getContext().getAssets(), "fonts/jameelnoorinastaleeq.ttf"); 

    tvDuaUrdu.setText(SingletonClass.duasUrd.get(index));
    tvDuaUrdu.setTypeface(ufont);
    tvDuaTranslit.setText(SingletonClass.duasTransl.get(index));








    if(engTransVisible)
    tvDuaRef.setText(SingletonClass.duasRefEng.get(index));
    else if (urdTransVisible)
    tvDuaRef.setText(SingletonClass.duasRefUrd.get(index));
    tvDuaRef.setTypeface(ufont);



    }

    int fontsize = FontSize.getFontSize();
    //Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/PDMS_Saleem_QuranFont-signed.ttf");
    tvDuaArabic.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize*2 );
    //tvDuaArabic.setTypeface(font);
    tvDuaEnglish.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize);
    tvDuaUrdu.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize);
    tvDuaRef.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 0.75));
    tvDuaTranslit.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 0.75));
    dividerEng.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 2));
    dividerUrdu.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 2));
    dividerRef.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 2));
    dividerTransl.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (fontsize * 2));

    boolean engTrans = new SharedPreferencesSupplication().read(SingletonClass.keyEngTrans, true);
    boolean urduTrans = new SharedPreferencesSupplication().read(SingletonClass.keyUrdTrans, false);
    boolean refVisible = new SharedPreferencesSupplication().read(SingletonClass.keyRef, false);
    boolean transVisible = new SharedPreferencesSupplication().read(SingletonClass.keyTransl, false);

    if (engTrans) {
        tvDuaEnglish.setVisibility(View.VISIBLE);
        dividerEng.setVisibility(View.VISIBLE);
    }
    else {
        tvDuaEnglish.setVisibility(View.GONE);
        dividerEng.setVisibility(View.GONE);
    }

    if (urduTrans) {
        tvDuaUrdu.setVisibility(View.VISIBLE);
        dividerUrdu.setVisibility(View.VISIBLE);
    }
    else {
        tvDuaUrdu.setVisibility(View.GONE);
        dividerUrdu.setVisibility(View.GONE);
    }

    if (refVisible) {
        tvDuaRef.setVisibility(View.VISIBLE);
        dividerRef.setVisibility(View.VISIBLE);
    }
    else {
        tvDuaRef.setVisibility(View.GONE);
        dividerRef.setVisibility(View.GONE);
    }   

    if (transVisible) {
    tvDuaTranslit.setVisibility(View.VISIBLE);
    dividerTransl.setVisibility(View.VISIBLE);
}
else {
    tvDuaTranslit.setVisibility(View.GONE);
    dividerTransl.setVisibility(View.GONE);
}

    if(!engTrans && !urduTrans){
        if(SingletonClass.duasAra.get(index)==""){
            tvDuaEnglish.setVisibility(View.VISIBLE);
            dividerEng.setVisibility(View.VISIBLE);
            //tvDuaEnglish.setText(SingletonClass.duasEng.get(index));
        }


    }

    if(!engTrans && !urduTrans && !transVisible && refVisible){
        tvDuaRef.setText(SingletonClass.duasRefEng.get(index));
    }

    svContent = (ScrollView) rootView.findViewById(R.id.sv_content);
    svContent.scrollTo(0, 0);


            super.onResume();
}


public int getPageNumber() {
    return mPageNumber;
}

Спасибо

1 Ответ

0 голосов
/ 20 декабря 2018

Я не уверен, но расширяет ли ваш адаптер FragmentPagerAdapter?Если это так, попробуйте расширить FragmentStatePagerAdapter.Я также рекомендую LeakCanary и профилировщик памяти Android Studio, чтобы проверить, протекают ли ваши фрагменты, или что-то в ваших фрагментах

...