I used the android.cupport-v4.jar compatibility library that android gives, I found a problem, I started creating a TabActivity containing several fragments in it.
I have a start tab with a GridView, from the element listener in the adapter I call the following code:
FragmentManager manager = getSupportFragmentManager(); FragmentTransaction ft = manager.beginTransaction(); ft.add(R.id.relativeLayoutContent, newFragment);
The problem is, when I open a new fragment and return to the first, it is not suitable for onAttach, because it was never attached, and since there was a new fragment, the activity now holds the last, but not the first, if I try to click an element again it will crash, telling me that the getActivity method from the fragment is null.
Any workaround for this?
source share