July 2015
Beginner to intermediate
600 pages
18h 59m
English
This all seems so complicated. Why not just set an instance variable on the CrimeFragment when it is created?
Because it would not always work. When the OS re-creates your fragment, either across a configuration change or when the user has switched out of your app and the OS reclaims memory, all of your instance variables will be lost. Also, remember that there is no way to cheat low-memory death, no matter how hard you try.
If you want something that works in all cases, you have to persist your arguments.
One option is to use the saved instance state mechanism. You can store the crime ID as a normal instance variable, save the crime ID in onSaveInstanceState(Bundle), and snag it ...
Read now
Unlock full access