Writers keep pens and notebooks by their bed so if they wake up in the middle of the night they can start writing right now. Or they have tape recorders. Anything works as long as it's immediately available. The iPhone has a "Music Memos" app, I'm sure there's something similar for Android. That's what I use.
Learning music theory and how to write music properly can come later. As long as you can sing, whistle, or hum a tune, you can record it.