Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - finish() closes app instead of the activity

I'm a begginer android programmer, and I seem to have a problem: I open new activitys, with

Intent newGameIntent = new Intent(actionName);
startActivity(newGameIntent);

and everythings works fine, the activity opens. but when i call finish() it doesnt goes to the previus activity, it just closes the app(no errors or other log messeges)

does anyone have an idea why is it happening? Thanks for your time!

by request, here is more of the code(of the stuff that i might have totally screwd up): first activity:

@Override
protected void onStop() {
    super.onStop(); 
    SplashScreen.sounds.releasSounds();
    finish();
}
@Override
protected void onPause() {
    super.onPause();
    pauseActivity();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    gameLoop.resumeThread();
    SplashScreen.sounds.resumeSounds();
}

private void pauseActivity() {
    gameLoop.pauseThread();
    SplashScreen.sounds.pauseBck();
}

and the first activity calling the seconds activity

Intent newGameIntent = new Intent("com.YuvalApps.menus.NEWGAMEMENU");
    startActivity(newGameIntent);

and for the seconds activity

    @Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();

}
like image 782
Yuval3210 Avatar asked Nov 04 '22 09:11

Yuval3210


1 Answers

When one activity was in background, The android system will invoke "onStop" method, But you invoke the method "finish" in method "onStop", So if you jump to another activity, the previous activity will destroyed by "onStop". You should remove "finish" in "onStop" method.

like image 153
Dawson Avatar answered Nov 11 '22 11:11

Dawson