我有一个活动,它从Internet加载数据,并且工作正常,除了o必须双击后退按钮才能完成它。我还注意到,在那些不连接到互联网的活动中,后退按钮从第一次单击起就起作用。当调试它时,我发现片段管理器回调正在处理,首先单击
FragmentManager.this.handleOnBackPressed();
来源
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();
}
}
尽管我不使用片段
我可以为您的问题提供临时解决方案,因为很难确切地了解是什么原因造成的。要解决此问题,您可以在“活动”中覆盖onBackPressed()
并在那里完成。
@Override
public void onBackPressed()
{
finish();
}