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

  • SEARCH
  • Home
  • 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 7398755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:54:36+00:00 2026-05-29T03:54:36+00:00

Here is my problem, when I start the Activity the Music start like I

  • 0

Here is my problem, when I start the Activity the Music start like I want it to, but when I leave the Activity (by pressing the back button) the Application crashes and “stopped unexpectedly” 🙁 All I want to do is have the audio STOP and go to another activity without the unexpected stop. How can I do this?

public class Run extends Activity {

/** The OpenGL View */
private GLSurfaceView glSurface;
private MediaPlayer mPlayer;

/**
 * Initiate the OpenGL View and set our own
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Create an Instance with this Activity
    glSurface = new GLSurfaceView(this);
    //Set our own Renderer and hand the renderer this Activity Context
    glSurface.setRenderer(new Lesson06(this));
    //Set the GLSurface as View to this Activity
    setContentView(glSurface);

    new Thread(new Runnable() {
        public void run() {
            try{
                MediaPlayer mPlayer = MediaPlayer.create(Run.this, R.drawable.theygonelovemeformyambition);
                mPlayer.setLooping(true);
                mPlayer.start();
                while(mPlayer.isPlaying()){
                    android.os.SystemClock.sleep(100);
                }
            }catch(Exception e){
                String TAG = null;
                Log.d(TAG,"ERROR PLAYING");
                e.printStackTrace();
            }
        }}).start();

}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    mPlayer.release();
}
}
  • 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-05-29T03:54:37+00:00Added an answer on May 29, 2026 at 3:54 am

    hi before you have to release media player resources. You should stop media player like below.

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
    
        if(mPlayer.isPlaying())
           mPlayer.stop();
    
        mPlayer.release();
    
        super.onDestroy();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok here is my problem: I'm going to start new activity when there isn't
Ok here is my problem : Before i start the description, let me to
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
Here I tried simple service program. Start service works fine and generates Toast but
I am having a similar problem as the person here: Android activity error I've
I am using implicit way to start an Activity . But when it runs,
ok am having a funny problem here, scenario is like this: Intent i of
In my application I use an AsyncTask on start up of my Activity to
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
What is the problem here? (Besides having redundant code). $.getJSON works as expected. However

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.