hello all,
I am working on android project. i have started background music in one of my activity named"myMainScreen.java"
now on that activity i have put one button.
while clicking on button i will redirected to another activity called"page_play.java" through intent.
Music will get stopped on the second activity(page_play).

but i want music in continuation, what changes i have to do in my current code.
my current code is given below.

public class myMainScreen extends Activity {

    MediaPlayer mp;
    AssetFileDescriptor asd;
    Button b1,b2;

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        b1 = (Button)findViewById(R.id.btn_play);

        b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent i = new Intent(myMainScreen.this,page_play.class);

   try {
            asd = getAssets().openFd("Background_Music.mp3");
            mp = new MediaPlayer();
            mp.setDataSource(asd.getFileDescriptor(), asd.getStartOffset(),asd.getLength());
        } catch (IOException e) {


    public void onPause()

Recommended Answers

You need to run your music as servive, you can see example here http://developer.android.com/guide/topics/media/mediaplayer.html#mpandservices

Jump to Post

All 2 Replies

Re: how to continue to play music on different activity 80 80

Thanks peter.It is very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.