On Mar 2, 12:41 pm, rishabh agrawal <[email protected]> wrote: > i have develope apps in which i play background music.but when i go to > the home through back tab then the song is also playing.how it is > stop.. my code are > MediaPlayer mp=MediaPlayer.create(this, R.raw.ri); > mp.start();
You are creating a MediaPlayer instance. You save a reference to this instance with your variable mp. You then start the music by calling one of the methods, with mp.start(). You then forget all about the instance, by not saving any reference to it. The local variable mp is gone, but the instance is still playing. This is like sitting in your car, starting the motor, turning on the radio of your car, then stepping out of your car as it rolls away from you. You should declare mp to be a member of your class, instead of a local variable. And at an opportune time, such as during your activity's onPause() callback, you should use the member mp to control the media playback. If this makes no sense to you at all, I'm afraid you should go find a much more basic introduction to Java and software development in general. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

