簡體   English   中英

從另一個片段傳遞到片段時,應用程序凍結一秒鍾

[英]App freezes for a second when passing to a fragment from another one fragment

我有一個關於片段的問題。當我從底部導航欄應用程序傳遞到另一個片段凍結一秒鍾,然后單擊該片段時,片段中包含很多元素,下面發布了一個示例代碼,另外兩個這樣的片段。我不知道如何解決這個問題。

View view;
private InterstitialAd mInterstitialAd;
Button saltanat,ankara,cumhuriyet,halifelik,cokpartili,medenikanun,anayasa,hukuk,kadinhaklari,
tevhiditedrisat,harfdevrimi,turktarih,turkdil,universite,tekkezaviye,sapka,soyadi,takvimsaat,iktisat,
kabotaj,saglik;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    MobileAds.initialize(getContext(),"ca-app-pub-3152282306923824/3545668936");
    mInterstitialAd = new InterstitialAd(getContext());
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    Window window = getActivity().getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(ContextCompat.getColor(getActivity(),R.color.colorPrimaryDark));
    view = inflater.inflate(R.layout.fragment_reformlar,container,false);
    saltanat = view.findViewById(R.id.saltanat_button);
    saltanat.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saltanatinKaldirilmasiGo(view);
        }
    });
    ankara = view.findViewById(R.id.baskent_button);
    ankara.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            baskentinIlaniGo(view);
        }
    });
    cumhuriyet = view.findViewById(R.id.cumhuriyet_reform_button);
    cumhuriyet.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cumhuriyetinIlaniGo(view);
        }
    });
    halifelik = view.findViewById(R.id.halifelik_button);
    halifelik.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            halifeliginKaldirilmasiGo(view);
        }
    });
    cokpartili = view.findViewById(R.id.cokpartili_button);
    cokpartili.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cokpartiliyeGecisGo(view);
        }
    });
    medenikanun = view.findViewById(R.id.medenikanun_button);
    medenikanun.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            medeniKanunGo(view);
        }
    });
    anayasa = view.findViewById(R.id.anayasa_button);
    anayasa.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            anayasaHareketleriGo(view);
        }
    });
    hukuk = view.findViewById(R.id.hukuk_button);
    hukuk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hukukInkilaplariGo(view);
        }
    });
    kadinhaklari = view.findViewById(R.id.kadinhaklari_button);
    kadinhaklari.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            kadinHaklariGo(view);
        }
    });
    tevhiditedrisat = view.findViewById(R.id.tevhiditedrisat_button);
    tevhiditedrisat.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tevhidiTedrisatGo(view);
        }
    });
    harfdevrimi = view.findViewById(R.id.harfdevrimi_button);
    harfdevrimi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            harfDevrimiGo(view);
        }
    });
    turktarih = view.findViewById(R.id.turktarihkurumu_button);
    turktarih.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            turkTarihKurumuGo(view);
        }
    });
    turkdil = view.findViewById(R.id.turkdilkurumu_button);
    turkdil.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            turkDilKurumuGo(view);
        }
    });
    universite = view.findViewById(R.id.universite_button);
    universite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            universiteReformuGo(view);
        }
    });
    tekkezaviye = view.findViewById(R.id.tekkevezaviye_button);
    tekkezaviye.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tekkeVeZaviyeGo(view);
        }
    });
    sapka = view.findViewById(R.id.sapkareformu_button);
    sapka.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sapkaReformuGo(view);
        }
    });
    soyadi = view.findViewById(R.id.soyadikanunu_button);
    soyadi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            soyadiKanunuGo(view);
        }
    });
    takvimsaat = view.findViewById(R.id.takvimvesaat);
    takvimsaat.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            takvimSaatGo(view);
        }
    });
    iktisat = view.findViewById(R.id.iktisat_button);
    iktisat.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            iktisatGo(view);
        }
    });
    kabotaj = view.findViewById(R.id.kabotaj_button);
    kabotaj.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            kabotajGo(view);
        }
    });
    saglik = view.findViewById(R.id.sosyalsaglik_button);
    saglik.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sosyalVeSaglikGo(view);
        }
    });
    return view;
}

感謝您的所有幫助。我在onCreate方法中使用AsyncTask解決了我的問題。

AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(ContextCompat.getColor(getApplicationContext(),R.color.colorPrimary));
            MobileAds.initialize(getApplicationContext(),"ca-app-pub-3152282306923824/3545668936");
            mInterstitialAd = new InterstitialAd(getApplicationContext());
            mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
        }
    });

而且我正在另一個空白處加載廣告。我也在按鈕上使用它。因為我正在使用按鈕來展示廣告。它的速度比以前更快。

private void loadAd() {
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    if(mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM