onBackPressed()不是第一次从AppCompatActivity调用

时间:2017-11-15 19:07:07

标签: android android-fragments onbackpressed

我有一系列片段,按顺序A>调用B> C来自用户互动。通过单击A中的“启动B”和从B中单击“启动C”来导航。

如果用户在C上并点击回来,我需要清除一个Activity级别变量,所以我有一个设置的接口/回调。当我的活动覆盖onBackPressed()时,将调用回调。

然后我在Fragment B上,我又回来了。这次没有调用onBackPressed()。再次按下它会调用它。

public interface BackOverrideCallback {
    void onBack();
}

private BackOverrideCallback mBackOverride;

private BackOverrideCallback mFragCBack = new BackOverrideCallback () {
    @Override
    public void onBack() {
        mVar = null;
        getSupportFragmentManager().popBackStack();
        mBackOverride = null;
    }
};

@Override
public void onBackPressed() {
    if (mBackOverride != null) {
        mBackOverride.onBack();
    } else {
        super.onBackPressed();
    }
}

我的API 19仿真器Logcat在背压不执行任何操作时显示:

com.android.systemui D/EGL_emulation: eglMakeCurrent: 0xb891dad0: ver 2 0
system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/KeypressStandard.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/KeypressSpacebar.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/KeypressDelete.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/KeypressReturn.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
system_process E/SoundPool: error loading /system/media/audio/ui/KeypressInvalid.ogg
system_process W/AudioService: Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
system_process W/AudioService: onLoadSoundEffects(), Error -1 while loading samples

API 27 Logcat显示了这个

? W/audio_hw_generic: Not supplying enough data to HAL, expected position 30719740 , only wrote 30719520
com.android.systemui D/EGL_emulation: eglMakeCurrent: 0xa59843c0: ver 2 0 (tinfo 0xa59835d0)
system_process D/AutofillManagerService: onBackKeyPressed()

0 个答案:

没有答案