Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Am new to Android Application development. I have created a simple slideshow application and added a mp3 to play background. Am working with Menu control currently.
I have a menu item named "Exit" trying to close the application when user click this item.

I have below code to close the application. This code close the application but does not stop the mp3 which runs in the application. Could you please help me to resolve this issue.

Thanks in Advance.

Java
public boolean onOptionsItemSelected(MenuItem item) {
		TextView lblDateTime = (TextView) findViewById(R.id.lblDateTime);
		 lblDateTime.setText(item.getItemId()); 
		 boolean result = false;
	  switch (item.getItemId()) {
	        case R.id.mnabout:
	   	     lblDateTime.setText("About selected"); 
	   	  result = true;
	   	  break;
	        case R.id.mnexit:
	        	//lblDateTime.setText("exit selected"); 
	        	result = true;
	        	this.finish();
	        	 break;
	        default:
	        	result = super.onOptionsItemSelected(item);
	        	 break;
	    }
		 return result;
	}


Regards,
Mahe
Posted
Comments
Sandeep Londhe 2-Sep-14 1:18am    
where is the mp3 code paste it also

1 solution

try this:


C#
public boolean onOptionsItemSelected(MenuItem item) {
            TextView lblDateTime = (TextView) findViewById(R.id.lblDateTime);
             lblDateTime.setText(item.getItemId());
             boolean result = false;
          switch (item.getItemId()) {
                case R.id.mnabout:
                 lblDateTime.setText("About selected");
              result = true;
              break;
                case R.id.mnexit:
                    //lblDateTime.setText("exit selected");

// mediaplayer is object of MediaPlayer class as you declared for playing mp3

              if(mediaplayer!=null && mediaplayer.isplaying()){
                    mediaplayer.stop();
                }



                    result = true;
                    this.finish();
                     break;
                default:
                    result = super.onOptionsItemSelected(item);
                     break;
            }
             return result;
        }
 
Share this answer
 
Comments
Mahendran Murugesan 2-Sep-14 1:40am    
Thank you for support.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900