Pedometer didn't work in the background

This is the best way to work in the background.

However, you may want to take a look into this. I believe it is related to your requirements.