Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9016573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:01:42+00:00 2026-06-16T04:01:42+00:00

When I am out of my app (when pressed home button or back button),

  • 0

When I am out of my app (when pressed home button or back button), the music keeps playing in the background. How can I stop it?

public class MainActivity extends Activity implements OnClickListener {

MediaPlayer ourSong;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ourSong = MediaPlayer.create(MainActivity.this, R.raw.girissong);
    ourSong.start();

    // codes

}

@Override
public void onClick(View v) {

    // some code

         }

         }

}

I made this code and it should stop when I go to next class and the next song will start

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:01:43+00:00Added an answer on June 16, 2026 at 4:01 am

    Place the below two methods in you class for stopping the Music play while navigating to other Screens and Home button respectively….

    @Override
    public void onPause()
    {
       super.onPause();
       if(ourSong.isPlaying())
       ourSong.stop();
       else
       return;
    }
    
    @Override
    public void onStop()
    {
       super.onStop();
      if(ourSong.isPlaying())
        ourSong.stop();
      else
       return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that crashes and freezes, I pressed home button to get
I have an iPhone app out there that calls home to my server every
I'm making a information app for Android and I can't figure out how to
Currently, my app loads a UIImagePickerController when a button is pressed. I would like
How can I assign actions on iOS when a user presses the home button
Basically my app randomly generates a string when pressed from out of an array.
In my app I have a button that when pressed opens a email whit
My app contained download button and whenever that button is pressed, I want some
Ok this question stems from this question: wp7: App failing! Can not figure out
I have an app, where when the button is pressed, an action happens ..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.