android-finish() 关闭应用程序而不是活动

Yuv*_*210 5 android android-intent activity-finish android-activity

我是一个初学者 android 程序员,我似乎有一个问题:我打开新活动,用

Intent newGameIntent = new Intent(actionName);
startActivity(newGameIntent);
Run Code Online (Sandbox Code Playgroud)

一切正常,活动打开。但是当我调用 finish() 时,它不会进入 previus 活动,它只是关闭应用程序(没有错误或其他日志消息)

有谁知道为什么会这样?谢谢你的时间!

根据要求,这里有更多代码(我可能完全搞砸的东西):第一个活动:

@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();
}
Run Code Online (Sandbox Code Playgroud)

和调用秒活动的第一个活动

Intent newGameIntent = new Intent("com.YuvalApps.menus.NEWGAMEMENU");
    startActivity(newGameIntent);
Run Code Online (Sandbox Code Playgroud)

和秒活动

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

}
Run Code Online (Sandbox Code Playgroud)

小智 3

当一个activity在后台时,android系统会调用“onStop”方法,但是你在“onStop”方法中调用了“finish”方法,所以如果你跳转到另一个activity,前一个activity将被“onStop”销毁。您应该删除“onStop”方法中的“finish”。