Maxsus qismga qayta yo'naltirildi

Mening ilovamda navigatsiya paneli bor, shuning uchun menda bitta MainActivity va qolgan qismlar bor. Mening ilovam yaxshi ishlamoqda. Men orqaga qaytib tugmani bosganimda, oldingi fragment.it ishini qaytadan bajara boshlaydi. Agar muvaffaqiyatli to'lovni amalga oshirganimdan so'ng, men muvaffaqiyatli to'lov sahifasini ko'rsam, foydalanuvchi sahifani qaytarish tugmasini bosib, HomeFragmentga yo'naltirishni istayman, lekin hozir u Placeorder fragmentiga joylashtiriladi.

@Override
    public void onBackPressed() {
        if(getFragmentManager().getBackStackEntryCount() == 0) {
            super.onBackPressed();
        }
        else {
            getFragmentManager().popBackStack();
        }
    }
1
to'lov muvaffaqiyatli bo'lganda, boshqa barcha qismlarni olib tashlang, SuccessfulPayment sahifasini ko'rsating, keyin bir necha soniyadan keyin uni olib tashlang
qo'shib qo'ydi muallif MohammedAlSafwan, manba
(agar siz faol faoliyatingizFragment.onBackPressed ()) bilan ishlayotgan bo'lsa, unda u yaxshi ishlaydi deb o'ylayman
qo'shib qo'ydi muallif Ram Koti, manba
buni qanday qilish kerak?
qo'shib qo'ydi muallif chris, manba

7 javoblar

Foydalanish:

fragmentTransaction.replace(R.id.fragment_container, mFeedFragment);
fragmentTransaction.commit();

Buni qilmang:

fragmentTransaction.addToBackStack(null);
0
qo'shib qo'ydi
oddiygina ushbu uy fragmentini chaqiring, ammo addToBackStack foydalanmaslik kerak
qo'shib qo'ydi muallif Rahul , manba
Haqiqatda, orqadagi tugmachani bironta joyga qaytarib olish kerak bo'lmasligi kerak, matbuotda faqatgina foydalanishni davom eting va tugma qo'shing va foydalanuvchini uyga olib keling.
qo'shib qo'ydi muallif Rahul , manba
Lekin qaerda buni chaqira olaman
qo'shib qo'ydi muallif chris, manba

onBackPress usulini bekor qiling:

@Override
public void onBackPressed() {
    if (fragment != null && fragment.getChildFragmentManager().getBackStackEntryCount() > 0){
    fragment.getChildFragmentManager().popBackStack();
    }else {
    super.onBackPressed();
    }
}
0
qo'shib qo'ydi

onBackPressed() ichida shunday qilishingiz mumkin:

@Override
    public void onBackPressed() {
        if(getSupportFragmentManger.findFragmentByTag("paymentFragment") != null){
          //add homeFragment;
        }  
        else{
            if(getFragmentManager().getBackStackEntryCount() == 0) {
                super.onBackPressed();
            }
            else {
                getFragmentManager().popBackStack();
            }
        }
    }
0
qo'shib qo'ydi

Funktsiyani abstrakt sinfdagi fragmentda quyida keltirish kerak

    /**
     * Handle "Back" key pressed.
     * @return TRUE if the "Back" key pressed was handled. FALSE indicate it's not handled and parent class can handle it.
     */
    public abstract boolean onBackPressed()

Va MainActivity'da siz ushbu funktsiyani bajarasiz

     @Override
    public void onBackPressed() {
        if (mSelectedFragment != null && mSelectedFragment.onBackPressed()) {
            return;
        } else {
            super.onBackPressed
        }
    }
0
qo'shib qo'ydi
parcha ko'rinadigan holatda, foydalanuvchi interfeysi bilan integratsiya bo'lishi mumkin
qo'shib qo'ydi muallif Phuoc Huynh, manba
yangilanganligini tekshiring ..
qo'shib qo'ydi muallif Phuoc Huynh, manba
mSelectedFragment nima?
qo'shib qo'ydi muallif chris, manba
qaerda bu usulni chaqira olaman?
qo'shib qo'ydi muallif chris, manba

Ushbu oddiy usuli amal qiling butun sonni bildiradi

 public int count;

bu sonni count = 0 sifatida boshlang

Endi bu sizning asosiy faoliyatingizga kiritilgan

  @Override
public void onBackPressed() {
    if (count == 1) {
        if (exit) {
            super.onBackPressed();
            return;
        } else {
            Toast.makeText(this, "Press Back again to Exit.", Toast.LENGTH_SHORT).show();
            exit = true;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    exit = false;
                }
            }, 2000);
        }
    }else {
        toolbar.setTitle("Home");
        mDrawerLayout.closeDrawers();
        count=1;
        display(0);
    }
}
0
qo'shib qo'ydi

Dastur sinfida va sizning faoliyatingiz ustidan qayta ishlangan bir necha global o'zgaruvchini (to'g'ri to'lov muvaffaqiyatli bo'lsa) sozlashingiz mumkin, chunki bu o'zgaruvchining haqiqiy yoki yo'qligini tekshiring.

  public void clearBackStack() {
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0) {
            FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
            manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }
0
qo'shib qo'ydi

Birinchidan, yangi fragman ochilganda va birinchi bo'lib yoki joyida bo'lganda siz bo'shlikda avvalgi qismni ( previousFragment ) o'zgartirasiz .... keyin previousFragment onBackPressed usulida, agar null bo'lsa, exit operatsiyasini amalga oshirsa, previousFragment bilan parchani almashtirishingiz mumkin.

0
qo'shib qo'ydi
avvalgi qismga o'tishni istamayman ... faqat to'lovni amalga oshirish uchun
qo'shib qo'ydi muallif chris, manba