Ancestral Navigation Qustion


#1

I used the technique in this chapter via NavUtil and the manifest to enable a View Fragment similar to CrimeFragment return to a parent activity which like CrimeListFragment is a ListView.

However what I am seeing is that when the “Up” button is pressed, the parent activity’s listfragment is being destroyed then recreated. I just thought it would be resumed.

I confirmed this with CriminalIntent this chapter. After testing I see that this is similar to startactivity(FLAG_ACTIVITY_CLEAR_TOP) as posited on pg,264 of book, which also destroy and recreates the parent activity/fragment as NavUtil does.

Is there a way when using fragments to make UP work like the back button and return to the previous listfragment without it being destroyed and rebuilt ala the back button? Or should I just punt on the UP button since the back button is doing what I need?

I like allowing the user to control the nav from the action bar rather than going down to the Back button. Thanks in advance!


#2

I have the exact same problem. @TheKog, have you found an answer?


#3

This seems to work for me:

Some suggested this, but it did not work for me:

Hope this helps.


#4

Thanks very much - I tried the popBackStack and it did nothing for me as well. BTW I am not using the NavUtil stuff at all - I just want it to go back :wink:

I got into BackPressed wackiness the other day trying to perform a SAVE/CANCEL dialog when the user hits the back key as he exits an “edit/new” fragment for an object. I read a lot of people trying to do it but its difficult because the onBackPressed handler is an Activity thing and there is no interface for it in the fragment. I messed around with setting things up so the fragment could override it but at that point the data I want to save and the fragment are not readily around by the time the activity onBackPressed is executed even though the fragment is retained. Something I will have to try again later. For now I can hook that up to the action bar “UP” quite nicely though :wink:


#5

Ran into some problem with getActivity().onBackPressed(); Ended up adding the following to my activity in the manifest and reverted back to NavUtil:

This solution was from here:
stackoverflow.com/questions/1329 … rent-state