Skip to content Skip to sidebar Skip to footer

Fragmentadapter Doesn't Hold The Good Reference Of The Fragment

I'm currently trying to work with fragment, but I'm stuck with an issue I can't solve. I have one activity, which holds 4 different fragment. From this activity, I launch an ASyncT

Solution 1:

I got the same problems once with Fragments, I was losing the current fragment after every screen rotation.

I simply solved it by adding one line in the Fragment class (not in the parent FragmentActivity class):

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Viewv= inflater.inflate(R.layout.rate_fragment, container,false);

    setRetainInstance(true);//Added not to lose the fragment instance during screen rotations

(...)

For your case where your app gets killed and opened again, I am not sure it will work though.

Post a Comment for "Fragmentadapter Doesn't Hold The Good Reference Of The Fragment"