How to get the focused / most recently opened fragment?
<p>I'm working on merging two android apps ready for ICS, currently mobile and tablet editions. The tablet edition uses fragments so I'm modifying the mobile version to use fragments too. The problem is that the back button is important part of the mobile edition and I do things like prompt for save when back is pressed. Fragments don't have onbackpressed so I plan to handle this using the activity that will call fragment.backPressed. But I can't find a way of getting the last opened fragment and I really don't want to keep track of all open and popbackstack operations.</p>

<p>I've tried backstackchanged listener but fragmentManager.getbackstackentryat(0).getid() always returns 0. Is there another way of finding the focused/most recently opened fragment?</p>

<p>Thanks,
Kev</p>
