OK, here's the solution and it's fairly straightforward once I thought about it in a more logical way.
What I have done is:-
- Create a public static int called activityCount.
- In the onCreate function of each activity I increment activityCount by 1.
- I @Override public void finish() and decrement activityCount by one and call super.finish().
- In onPause if activityCount == 1, pause the music.
- In onResume if activityCount == 1, play the music.
This is giving me the desired effect by continuously playing the music but when the home button is clicked the music stops and resumes when the activity is resumed.
Thanks for all the suggestions as it helped me think more logically.