3

I have an activity that load data from internet and it works fine except that o have to double click back button to finish it. I also noticed that in the activities that don't connect to internet back button works from first click. and when debugging it i found that fragment manager callback is handling first click

        FragmentManager.this.handleOnBackPressed();

from source

void handleOnBackPressed() {
    // First, execute any pending actions to make sure we're in an
    // up to date view of the world just in case anyone is queuing
    // up transactions that change the back stack then immediately
    // calling onBackPressed()
    execPendingActions();
    if (mOnBackPressedCallback.isEnabled()) {
        // We still have a back stack, so we can pop
        popBackStackImmediate();
    } else {
        // Sigh. Due to FragmentManager's asynchronicity, we can
        // get into cases where we *think* we can handle the back
        // button but because of frame perfect dispatch, we fell
        // on our face. Since our callback is disabled, we can
        // re-trigger the onBackPressed() to dispatch to the next
        // enabled callback
        mOnBackPressedDispatcher.onBackPressed();
    }
}

although i don't use fragment

Islam Assem
  • 1,376
  • 13
  • 21

0 Answers0