I have an activity that holds a fragment, when something on that fragment gets clicked i replace that fragment with another fragment. If the device is rotated with in the second fragment then the onCreate gets called for the activity and recreates the first fragment again.
How can I stop the onCreate from getting called when the device rotates?
in my manifest i have this
<activity android:name="CalActivity" android:configChanges="orientation|keyboardHidden"/>
it is my understanding that adding in the configChanges to that activity prevents the activity from being destroyed and recreated but the onCreate still gets called and messes up the fragments.
I also tried putting in setRetainInstance() in the fragments and that didnt help either
if the device does not rotate the the fragments work like they should and I dont want to make this a one orientation only activity, thats more of a hack than actually fixes the problem
What else can I do?
EDIT:
this is how I create my fragments
Fragment miniMonthFrag = new MonthByWeekFragment(System.currentTimeMillis(), false);
ft.replace(R.id.cal_frame, miniMonthFrag).commit();
Instead of using replace use:
This will make sure you use the pre-existing fragment after a rotate.