我可以从我的 mainActivity 进入我的 SoundActivity 类,这是一个菜单。但是,当我单击设备后退按钮时,它不会返回到我的 mainActivity,而只会关闭应用程序。我已将完成()放在最后,但这似乎没有用。我也尝试过 super.backPressed() ,但也没有用。这是声音类的代码
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.ToggleButton;
public class SoundActivity extends Activity
{
MediaPlayer ourSong;
private SeekBar volumeSeekbar = null;
private ToggleButton muteButton = null;
private AudioManager audioManager = null;
private AudioManager mAm;
private boolean mIsMute;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.soundmenu);
initControls();
ourSong = MediaPlayer.create(SoundActivity.this, R.raw.beat2);
ourSong.start();
}
private void initControls()
{
try
{
volumeSeekbar = (SeekBar)findViewById(R.id.sbVolumeBar);
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
volumeSeekbar.setMax(audioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
volumeSeekbar.setProgress(audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC));
volumeSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
public void onStopTrackingTouch(SeekBar arg0)
{
}
public void onStartTrackingTouch(SeekBar arg0)
{
}
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
{
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, 0);
}
});
muteButton = (ToggleButton)findViewById(R.id.toggleButton1);
muteButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
if(muteButton.isChecked())
{
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
}
else
{
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
如果有人可以帮助我,我将不胜感激。此刻一头雾水
好的,这是启动声音活动的 mainActivity
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
import android.os.Bundle;
public class PinballShooterActivity extends Activity {
/** Called when the activity is first created. */
MediaPlayer ourSong;
private ToggleButton muteButton = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ourSong = MediaPlayer.create(PinballShooterActivity.this, R.raw.beat2);
ourSong.start();
Button soundBtn = (Button) findViewById(R.id.sound);
soundBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(PinballShooterActivity.this, SoundActivity.class));
}
});
Button highScrBtn = (Button) findViewById(R.id.highscores);
highScrBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(PinballShooterActivity.this, HighScoreActivity.class));
}
});
Button gameBtn = (Button) findViewById(R.id.startgame);
gameBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(PinballShooterActivity.this, GameActivity.class));
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
这是android清单
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SoundActivity" />
<activity
android:name=".HighScoreActivity" />
<activity
android:name=".GameActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.pinball.shooter.GAMEACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PinballShooterActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.pinball.shooter.faiz.PINBALLSHOOTERACTIVITY"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>