I have a MainActivity.java as it follows:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
}
public void startGame(View v){
Intent i = new Intent(MainActivity.this, StartGame.class);
startActivity(i);
}
And my StartGame class as it follows:
public class StartGame extends AppCompatActivity {
private Game game;
private Handler updateHandler;
public static Sound sound;
public static Activity activity = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
sound = new Sound(this);
game = new Game(this, 3, 0);
setContentView(game);
CreateHandler();
UpdateThread myThread = new UpdateThread(updateHandler);
myThread.start();
activity = this;
}
private void CreateHandler() {
updateHandler = new Handler() {
public void handleMessage(Message msg) {
game.invalidate();
game.update();
super.handleMessage(msg);
}
};
}
protected void onPause() {
super.onPause();
game.pauseGame();
}
protected void onResume() {
super.onResume();
game.resumeGame();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
My question here is:
I'm in MainActivity.java and I successfully start a new instance of StartGame through a Button (which fires me the game with and onDraw). Now, if the user presses the soft back button (Navigation bar), the activity will close and the MainActivity layout would come up, but I can still hear the sounds of the game running in the background (even if I go to the Home Screen), meaning that the activity is still running.
I've added the onBackPressed method to StartGame.java but it seems not to work.
Anyone has some clues on what's going on? :/