I have been stuck on this for days. I have an activity. I implemented
@Override
public void onBackPressed() {
Log.e("TEST", "Pressed back");
mAdapter.back();
}
The layout is a view pager and I have a FragmentStatePagerAdapter I extended managing it. I have tabs and I wanted to manage their history , so I implemented history logic as explained in https://stackoverflow.com/a/17832632/3821037 . It works fine but for some reason after I click to change a tab and hit on the android back button the first time I click isn't register - it doesn't call the activity OnBackPressed. The second call works fine. Does anyone know where the first event goes to? I should say that I never leave that same activity. I can also see the first event logged
05-20 12:44:17.952: I/ViewRootImpl(22749): ViewRoot's KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=8406029, downTime=8406029, deviceId=-1, source=0x101 } to com.android.internal.policy.impl.PhoneWindow$DecorView{428bba20 V.E..... R....... 0,0-1080,1776}
Yet I'm not sure which object gets it (I also tried to add a listener on the view of the fragment and the viewPager, and also all the parents of the activity's root view - nothing is receiving it).
Thank you.