注册关闭Android应用程序 [英] Reg Closing the Android Application

查看:71
本文介绍了注册关闭Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是Android应用程序开发的新手。我创建了一个简单的幻灯片应用程序并添加了一个mp3来播放背景。我正在使用Menu控件。

我有一个名为Exit的菜单项试图在用户点击这个项目时关闭应用程序。



我有以下代码来关闭应用程序。此代码关闭应用程序但不会停止在应用程序中运行的mp3。你能帮我解决这个问题吗?



先谢谢。



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.

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;
	}





问候,

Mahe



Regards,
Mahe

推荐答案

试试这个:





try this:


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;
        }


这篇关于注册关闭Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆