After a long and arduous journey of getting a navigation drawer set up for the redesign of my ChemPal app, I finally completed a wonderful and beautiful hamburger menu that I was greatly happy with.

Because of how I have my app divided up—a main app file (the main activity) and a library full of all the functions and other Fragment and Activity classes—I decided it was important to move all the navigation-drawer-related code (of which there is a fair amount) to a helper class called ViewOwner.

This worked marvelously at first. It was all in another class, away and free from infecting my main activity file. Until I turned on the orientation changer. And every time I changed it, it would go blank. Worse yet, when I did so, the button to open and close it stopped functioning also.

I did what any debugger would do and inserted a bajillion print statements into my functions (such as getView() and getCount() of the adapter) to see what was going wrong. Somehow, getCount() was returning a value greater than 0, but getView() was never called.

After two hours (maybe more, I get delusional after a while) of random debugging attempts, I realized that on recreate, Android actually creates a NEW activity—it doesn't call recreate() on the old one. Thus, in the helper class, it was still setting everything for the original Activity's menu.

Hurr, durr, durr. The moral of the story is: If you're using helper methods, make sure they're using updated data. This has been a public service announcement from Frustrated Java Programmers, Incorporated.

Next Post Previous Post