There is such a law but you should not assume it means what you think it means. Talk to a legal professional if it's important to you. One IP lawyer I interacted with maintained that the rulings in actual court practice are very unfavorable to the moonlighting employees. To the point that CA labor code 2870 might as well not exist (although of course he didn't say that in so many words.) "Actual or demonstrably anticipated research or development of the employer" can be made to mean anything. I asked, "Say I worked for a company that makes software for medical devices, and I work on cell phone apps in my spare time, could they still claim that it's related to their research and development?" He said, "Yes."
I hear you. While living at my prior location, I was always integrating plausible deniability into my business plans and their initial implementations, besides keeping my work super secret. Now I don't worry about the secrecy, and feel more relaxed about deniability. (Not that I've been doing anything seriously since I moved here --- I like my team, and I would like to accomplish big things with them.)
That sucks. "Actual or demonstrably anticipated research" looks like a fairly clear attempt to make sure that companies can't just claim that they might be planning to go into some unrelated field, and it's unfortunate the courts don't see it that way.