"An app is active when it is receiving events. An active app can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked."
First, I was a little vague. When I said OS makers, I was referring only to iOS and Android, Mac, Linux and Windows apps are always active when in the background.
As for how they receive notifications while in the background. On iOS (and I'm sure Android is similar), apps register notification events with the OS and the OS sends a notification to the app for that specific event. For example you can register a specific number geographical areas and get notified when a user enters or leaves those areas. Your app is still in the background, but you can perform some small task in response to that event[1].
Your app can also get push notifications over the network or timed notification while in the background. For example a podcast app might get signaled that a new episode is ready and download that episode.
Backgrounded apps can also pop notifications which put alerts up and trigger a sound/ vibration. That's how most notifications get done.
The type of notifications you can get is pretty limited though and the accelerometer is not one of the things you can listen for.
There are also a few specific things apps can do while in the background[2] which generally prevents them from being killed. Media playback is the big one. But again, access to notifications and events like the accelerometer data is quite limited. I believe fitness apps might have access to accelerometer data while in the background, but I'm not sure.
[1] This has been abused and it's been a big game of cat and mouse.
Is it any different from going to the Home screen first prior to pressing the sleep/wake button?