My app has 1 activity with some fragments in it. But when I go into my fragment (JungleInfo) I then hit the menu button and go to the "Display" section of my phone to change the font of my android device Ex) Normal to Large or Large to Normal. Once I do that I open my app again thinking that the text in my app should grow/shrink and still be on the same fragment like I have seen in other apps but instead it just crashes.
This Log.i code snippet here is when I go from Activity (MainActivity) -> ListFragment (JungleList-Fragment) -> Fragment (JungleInfo-Fragment)
10-01 12:47:45.193: I/MainActivity(1039): onCreate
10-01 12:47:45.453: I/MainActivity(1039): onStart
10-01 12:47:45.483: I/MainActivity(1039): onResume
10-01 12:47:50.913: I/Jungle-ListFragment(1039): onAttach
10-01 12:47:50.923: I/Jungle-ListFragment(1039): onCreateView
10-01 12:47:50.993: I/Jungle-ListFragment(1039): onActivityCreated
10-01 12:47:52.244: I/Jungle-ListFragment(1039): onDestroyView
10-01 12:47:52.244: I/JungleInfo-Fragment(1039): onAttach
10-01 12:47:52.244: I/JungleInfo-Fragment(1039): onCreate
10-01 12:47:52.244: I/JungleInfo-Fragment(1039): onCreateView
10-01 12:47:52.924: I/JungleInfo-Fragment(1039): onActivityCreated
Now I just went and changed the devices font size and then re-entered my app and this is what I get:
10-01 12:48:23.533: I/JungleInfo-Fragment(1039): onPause
10-01 12:48:23.533: I/MainActivity(1039): onPause
10-01 12:48:24.253: I/MainActivity(1039): onStop
10-01 12:48:54.313: I/JungleInfo-Fragment(1039): onDestroyView
10-01 12:48:54.373: I/MainActivity(1039): onDestroy
10-01 12:48:54.483: I/Jungle-ListFragment(1039): onAttach
10-01 12:48:54.503: I/JungleInfo-Fragment(1039): onAttach
10-01 12:48:54.503: I/JungleInfo-Fragment(1039): onCreate
10-01 12:48:54.503: I/MainActivity(1039): onCreate
10-01 12:48:55.423: I/JungleInfo-Fragment(1039): onCreateView
10-01 12:48:55.483: D/AndroidRuntime(1039): Shutting down VM
10-01 12:48:55.483: W/dalvikvm(1039): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-01 12:48:55.513: E/AndroidRuntime(1039): FATAL EXCEPTION: main
10-01 12:48:55.513: E/AndroidRuntime(1039): java.lang.RuntimeException: java.lang.NullPointerException
I traced this to find what was being null and I found this out,
In my JungleInfo class I have this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
jungleChoice = ((MainActivity)getActivity()).fragmentDataJungle.toString(); //This is null when the app gets loaded up again after a device font change.
...
}
Now the first run through it isn't null becuase I am using this to tell the next fragment what the user selected in the ListFragment but when I exit out to change the device font and then re-enter the app it is now null.
From what I have gethered on other StackOverflow questions and the android developer page, http://developer.android.com/reference/android/app/Fragment.html#Layout I think I need to do something either in my Activity or Fragments lifecycle (specifically in onPause(), onResume() or from what I gathered about Fragments in of my onCreateView() method since that deals with savedInstanceState) to save what is retained in jungleChoice. But if this is the case I don't know how to save this in onPause() and then load it back up in onResume()/onCreateView(). Could anyone shed some light on what my problem is here or a possible solution?