菜单的第二个"ITEM2"是“退出”,怎么给它写退出整个程序的代码,还有关闭正在播放的音乐,让程序内用MediaPlayer调用播放的音乐停止?  现在退出时音乐还在放。music.stop();貌似不能加在case里面啊?@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case ITEM:
Intent intent = new Intent();
intent.setClass(this, mineDear.class);
startActivity(intent);
return true;
// break;
case ITEM2: break;
default:
break;
}
return true;
}

解决方案 »

  1.   

    int nPid = android.os.Process.myPid();
    android.os.Process.killProcess(nPid);
    finish();
    System.exit(0);
      

  2.   

    推出代码:
    int sdk_Version = android.os.Build.VERSION.SDK_INT;
    if (sdk_Version >= 8) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);
    System.exit(0);
    } else if (sdk_Version < 8) {
    ActivityManager activityMgr = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    activityMgr.restartPackage(getPackageName());
    }更多内容欢迎访问:http://dalvik.co.cc
      

  3.   

    退出Android程序代码:    int sdk_Version = android.os.Build.VERSION.SDK_INT;
            if (sdk_Version >= 8) {
                Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_HOME);
                startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(startMain);
                System.exit(0);
            } else if (sdk_Version < 8) {
                ActivityManager activityMgr = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                activityMgr.restartPackage(getPackageName());
            }
    更多内容欢迎访问:http://dalvik.co.cc
      

  4.   

    退出Android程序代码:    int sdk_Version = android.os.Build.VERSION.SDK_INT;
            if (sdk_Version >= 8) {
                Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_HOME);
                startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(startMain);
                System.exit(0);
            } else if (sdk_Version < 8) {
                ActivityManager activityMgr = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                activityMgr.restartPackage(getPackageName());
            }
    更多内容欢迎访问:http://dalvik.co.cc
      

  5.   

    看看这个 http://wenku.baidu.com/view/f0263d3e580216fc700afda9.html